Parameters and Variables

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 1303
Joined: 29 Sep 2013, 22:18

Parameters and Variables

21 Nov 2015, 03:27

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.
Peabianjay
Posts: 52
Joined: 07 Nov 2015, 22:50

Re: Parameters and Variables

21 Nov 2015, 04:14

Is this what you want?

Code: Select all

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

test( variablename, x )

test( a, b )
{
    msgbox, % a " has the value " b
}
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Parameters and Variables

21 Nov 2015, 04:26

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...

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: garry and 181 guests