SetEnv (Var = Value)

Assigns the specified value to a variable.

Deprecated: This command or a legacy assignment is not recommended for use in new scripts. Use expression assignments like Var := Value instead.

SetEnv, Var, Value
Var = Value

Parameters

Var

The name of the output variable in which to store Value.

Value

The string or number to store. If the string is long, it can be broken up into several shorter lines by means of a continuation section, which might improve readability and maintainability.

Remarks

By default, any spaces or tabs at the beginning and end of Value are omitted from Var. To prevent this, use the methods described at AutoTrim Off.

The name "SetEnv" is misleading and is a holdover from AutoIt v2. Unlike AutoIt v2, AutoHotkey does not store its variables in the environment. This is because performance would be worse and also because the OS limits the size of each environment variable to 32 KB. Use EnvSet instead of SetEnv to write to an environment variable.

The memory occupied by a large variable can be freed by setting it equal to nothing, e.g. Var =.

It is possible to create a pseudo-array with this command and any others that accept an output variable. This is done by appending a variable reference to the output variable name, e.g. array%i% = 123. See Arrays for more details.

Assign expression (:=), AutoTrim, EnvSet, EnvAdd, EnvSub, EnvMult, EnvDiv, If (legacy), Arrays

Examples

Assigns a string to a variable.

Var1 = This is a string.

Assigns a number to a variable.

Color2 = 450

Assigns the value of Var1 to a variable.

Var1 = This is a string.
Color3 = %Var1%

Assigns the value of A_TickCount to a pseudo-array variable.

i = 1
Array%i% = %A_TickCount%