PageRenderTime 41ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/docs/commands/SetExpression.htm

https://github.com/Lexikos/AutoHotkey_L-Docs
HTML | 70 lines | 59 code | 11 blank | 0 comment | 0 complexity | b2a4471ec2fe241a70f710ef1e9e2c2a MD5 | raw file
  1. <!DOCTYPE HTML>
  2. <html lang="en">
  3. <head>
  4. <title>Var := Expression - Syntax &amp; Usage | AutoHotkey</title>
  5. <meta name="description" content="The &quot;Var := Expression&quot; statement evaluates an expression and stores the result in a variable." />
  6. <meta name="ahk:equiv-v2" content="Variables.htm#AssignOp" />
  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>Var := expression</h1>
  14. <p>Evaluates an expression and stores the result in a <a href="../Variables.htm">variable</a>.</p>
  15. <pre class="Syntax">Var := expression</pre>
  16. <h2 id="Parameters">Parameters</h2>
  17. <dl>
  18. <dt>Var</dt>
  19. <dd><p>The name of the <a href="../Variables.htm">variable</a> in which to store the result of <em>expression</em>.</p></dd>
  20. <dt>Expression</dt>
  21. <dd><p>See <a href="../Variables.htm#Expressions">expressions</a> and the examples below for details.</p></dd>
  22. </dl>
  23. <h2 id="Remarks">Remarks</h2>
  24. <p>The := operator is optimized so that it performs just as quickly as the = operator for simple cases such as the following:</p>
  25. <pre>x := y <em>; Same performance as x = %y%</em>
  26. x := 5 <em>; Same performance as x = 5.</em>
  27. x := "literal string" <em>; Same performance as x = literal string.</em></pre>
  28. <p>The words <code>true</code> and <code>false</code> are built-in constants containing 1 and 0. They can be used to make a script more readable as in these examples:</p>
  29. <pre>CaseSensitive := false
  30. ContinueSearch := true</pre>
  31. <p>It is possible to create a <a href="../misc/Arrays.htm#pseudo">pseudo-array</a> with this command and any others that accept an <em>OutputVar</em>. This is done by making <em>OutputVar</em> contain a reference to another variable, e.g. <code>Array%i% := Var/100 + 5</code>. See <a href="../misc/Arrays.htm">Arrays</a> for more information.</p>
  32. <h2 id="Related">Related</h2>
  33. <p><a href="../Variables.htm#Expressions">Expressions</a>, <a href="IfExpression.htm">If (expression)</a>, <a href="../Functions.htm">Functions</a>, <a href="SetEnv.htm">SetEnv</a>, <a href="EnvSet.htm">EnvSet</a>, <a href="EnvAdd.htm">EnvAdd</a>, <a href="EnvSub.htm">EnvSub</a>, <a href="EnvMult.htm">EnvMult</a>, <a href="EnvDiv.htm">EnvDiv</a>, <a href="IfEqual.htm">If (legacy)</a>, <a href="../misc/Arrays.htm">Arrays</a></p>
  34. <h2 id="Examples">Examples</h2>
  35. <div class="ex" id="ExString">
  36. <p><a class="ex_number" href="#ExString"></a> Assigns a literal string to a variable.</p>
  37. <pre>Var := "literal string"</pre>
  38. </div>
  39. <div class="ex" id="ExNumber">
  40. <p><a class="ex_number" href="#ExNumber"></a> Assigns a number to a variable.</p>
  41. <pre>Var := 3</pre>
  42. </div>
  43. <div class="ex" id="ExMath">
  44. <p><a class="ex_number" href="#ExMath"></a> Calculates the net price and stores the result in <var>Var</var>.</p>
  45. <pre>Var := Price * (1 - Discount/100)</pre>
  46. </div>
  47. <div class="ex" id="ExBoolean">
  48. <p><a class="ex_number" href="#ExBoolean"></a> Determines the truth of an expression and stores the result (1 for true or 0 for false) in <var>Finished</var>.</p>
  49. <pre>Finished := not Done or A_Index &gt; 100
  50. if not Finished
  51. {
  52. FileAppend, %NewText%`n, %TargetFile%
  53. return
  54. }
  55. else
  56. ExitApp</pre>
  57. </div>
  58. </body>
  59. </html>