Page 1 of 1

Parameters and Variables

Posted: 21 Nov 2015, 03:27
by PuzzledGreatly
Within a function parameters can't be variables but how to create a GUI variable inside a function without declaring the variable as global or static in advance? Is there anyway to pass a variable name into a function? Thanks.

Re: Parameters and Variables

Posted: 21 Nov 2015, 04:14
by Peabianjay
Is this what you want?

Code: Select all

variablename := "x"
%variablename% := 5

test( variablename, x )

test( a, b )
{
    msgbox, % a " has the value " b
}

Re: Parameters and Variables

Posted: 21 Nov 2015, 04:26
by lexikos
PuzzledGreatly wrote:Within a function parameters can't be variables
Parameters are variables.

I assume what you mean is that you cannot use parameters as GUI variables. That is because parameters are non-static local variables. You cannot use non-static local variables as GUI variables.
how to create a GUI variable inside a function without declaring the variable as global or static in advance?
If the variable already exists as a static or global variable and not as a non-static local variable, you can just pass vvariablename to the Gui command without prior declaration. Otherwise, you must either explicitly declare the variable or make the function assume-global or assume-static.
Is there anyway to pass a variable name into a function?
Yes, the same ways that you pass any other string into a function...