/docs/commands/SetExpression.htm
HTML | 70 lines | 59 code | 11 blank | 0 comment | 0 complexity | b2a4471ec2fe241a70f710ef1e9e2c2a MD5 | raw file
- <!DOCTYPE HTML>
- <html lang="en">
- <head>
- <title>Var := Expression - Syntax & Usage | AutoHotkey</title>
- <meta name="description" content="The "Var := Expression" statement evaluates an expression and stores the result in a variable." />
- <meta name="ahk:equiv-v2" content="Variables.htm#AssignOp" />
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <link href="../static/theme.css" rel="stylesheet" type="text/css" />
- <script src="../static/content.js" type="text/javascript"></script>
- </head>
- <body>
- <h1>Var := expression</h1>
- <p>Evaluates an expression and stores the result in a <a href="../Variables.htm">variable</a>.</p>
- <pre class="Syntax">Var := expression</pre>
- <h2 id="Parameters">Parameters</h2>
- <dl>
- <dt>Var</dt>
- <dd><p>The name of the <a href="../Variables.htm">variable</a> in which to store the result of <em>expression</em>.</p></dd>
- <dt>Expression</dt>
- <dd><p>See <a href="../Variables.htm#Expressions">expressions</a> and the examples below for details.</p></dd>
- </dl>
- <h2 id="Remarks">Remarks</h2>
- <p>The := operator is optimized so that it performs just as quickly as the = operator for simple cases such as the following:</p>
- <pre>x := y <em>; Same performance as x = %y%</em>
- x := 5 <em>; Same performance as x = 5.</em>
- x := "literal string" <em>; Same performance as x = literal string.</em></pre>
- <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>
- <pre>CaseSensitive := false
- ContinueSearch := true</pre>
- <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>
- <h2 id="Related">Related</h2>
- <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>
- <h2 id="Examples">Examples</h2>
- <div class="ex" id="ExString">
- <p><a class="ex_number" href="#ExString"></a> Assigns a literal string to a variable.</p>
- <pre>Var := "literal string"</pre>
- </div>
- <div class="ex" id="ExNumber">
- <p><a class="ex_number" href="#ExNumber"></a> Assigns a number to a variable.</p>
- <pre>Var := 3</pre>
- </div>
- <div class="ex" id="ExMath">
- <p><a class="ex_number" href="#ExMath"></a> Calculates the net price and stores the result in <var>Var</var>.</p>
- <pre>Var := Price * (1 - Discount/100)</pre>
- </div>
- <div class="ex" id="ExBoolean">
- <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>
- <pre>Finished := not Done or A_Index > 100
- if not Finished
- {
- FileAppend, %NewText%`n, %TargetFile%
- return
- }
- else
- ExitApp</pre>
- </div>
- </body>
- </html>