If Var between Low and High - Syntax & Usage | AutoHotkey

AutoHotkey

If var [not] between LowerBound and UpperBound

Checks whether a variable's contents are numerically or alphabetically between two values (inclusive).

if Var between LowerBound and UpperBound
if Var not between LowerBound and UpperBound

Parameters

Var

The variable name whose contents will be checked.

LowerBound

To be within the specified range, Var must be greater than or equal to this string, number, or variable reference.

UpperBound

To be within the specified range, Var must be less than or equal to this string, number, or variable reference.

Remarks

If all three of the parameters are purely numeric, they will be compared as numbers rather than as strings. Otherwise, they will be compared alphabetically as strings (that is, alphabetical order will determine whether Var is within the specified range). In that case, StringCaseSense On can be used to make the comparison case sensitive.

Caution: The operators "between", "is", "in", and "contains" are not supported in expressions.

Related

IfEqual/Greater/Less, if var in/contains MatchList, if var is type, IfInString, StringCaseSense, EnvAdd, Blocks, Else

Example

if var between 1 and 5
    MsgBox, %var% is in the range 1 to 5, inclusive.

if var not between 0.0 and 1.0
    MsgBox %var% is not in the range 0.0 to 1.0, inclusive.

if var between %VarLow% and %VarHigh%
    MsgBox %var% is between %VarLow% and %VarHigh%.

if var between blue and red
    MsgBox %var% is alphabetically between the words blue and red.

LowerLimit = 1
UpperLimit = 10
InputBox, UserInput, Enter a number between %LowerLimit% and %UpperLimit%
if UserInput not between %LowerLimit% and %UpperLimit%
    MsgBox Your input is not within the valid range.