Parameters and Variables

Get help with using AutoHotkey and its commands and hotkeys
User avatar
PuzzledGreatly
Posts: 923
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: 47
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: 7088
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

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”

Who is online

Users browsing this forum: boiler, c7aesa7r, mikeyww, PuzzledGreatly, TheProdigyC2, zKade and 34 guests