PageRenderTime 38ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/commands/IfBetween.htm

http://github.com/Lexikos/AutoHotkey_L-Docs
HTML | 67 lines | 54 code | 13 blank | 0 comment | 0 complexity | a04e8ad44005c60d94dc10984d47130b MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>If Var between Low and High - Syntax &amp; Usage | AutoHotkey</title>
  5. <meta name="description" content="The &quot;if Var between Low and High&quot; statement checks whether a variable's contents are numerically or alphabetically between two values (inclusive)." />
  6. <meta name="ahk:equiv-v2" content="commands/IfExpression.htm" />
  7. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  8. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  9. <link href="../static/theme.css" rel="stylesheet" type="text/css" />
  10. <script src="../static/content.js" type="text/javascript"></script>
  11. </head>
  12. <body>
  13. <h1>If var [not] between LowerBound and UpperBound</h1>
  14. <p>Checks whether a <a href="../Variables.htm">variable's</a> contents are numerically or alphabetically between two values (inclusive).</p>
  15. <pre class="Syntax">
  16. <span class="func">if</span> Var <span class="func">between</span> LowerBound <span class="func">and</span> UpperBound
  17. <span class="func">if</span> Var <span class="func">not between</span> LowerBound <span class="func">and</span> UpperBound
  18. </pre>
  19. <h2>Parameters</h2>
  20. <dl>
  21. <dt>Var</dt>
  22. <dd><p>The <a href="../Variables.htm">variable</a> name whose contents will be checked.</p></dd>
  23. <dt>LowerBound</dt>
  24. <dd><p>To be within the specified range, <em>Var</em> must be greater than or equal to this string, number, or variable reference.</p></dd>
  25. <dt>UpperBound</dt>
  26. <dd><p>To be within the specified range, <em>Var</em> must be less than or equal to this string, number, or variable reference.</p></dd>
  27. </dl>
  28. <h2>Remarks</h2>
  29. <p>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 <em>Var</em> is within the specified range). In that case, <code><a href="StringCaseSense.htm">StringCaseSense</a> On</code> can be used to make the comparison case sensitive.</p>
  30. <p class="warning"><strong>Caution</strong>: The operators &quot;between&quot;, &quot;is&quot;, &quot;in&quot;, and &quot;contains&quot; are not supported in <a href="../Variables.htm#Expressions">expressions</a>.</p>
  31. <h2>Related</h2>
  32. <p><a href="IfEqual.htm">IfEqual/Greater/Less</a>, <a href="IfIn.htm">if var in/contains MatchList</a>, <a href="IfIs.htm">if var is type</a>, <a href="IfInString.htm">IfInString</a>, <a href="StringCaseSense.htm">StringCaseSense</a>, <a href="EnvAdd.htm">EnvAdd</a><a href="Block.htm">, Blocks</a>, <a href="Else.htm">Else</a></p>
  33. <h2>Examples</h2>
  34. <div class="ex" id="ExBasic">
  35. <p><a href="#ExBasic">#1</a></p>
  36. <pre>if var between 1 and 5
  37. MsgBox, %var% is in the range 1 to 5, inclusive.
  38. if var not between 0.0 and 1.0
  39. MsgBox %var% is not in the range 0.0 to 1.0, inclusive.
  40. if var between %VarLow% and %VarHigh%
  41. MsgBox %var% is between %VarLow% and %VarHigh%.
  42. if var between blue and red
  43. MsgBox %var% is alphabetically between the words blue and red.</pre>
  44. </div>
  45. <div class="ex" id="ExInputBox">
  46. <p><a href="#ExInputBox">#2</a></p>
  47. <pre>LowerLimit := 1
  48. UpperLimit := 10
  49. InputBox, UserInput, Enter a number between %LowerLimit% and %UpperLimit%
  50. if UserInput not between %LowerLimit% and %UpperLimit%
  51. MsgBox Your input is not within the valid range.</pre>
  52. </div>
  53. </body>
  54. </html>