Thursday, September 4, 2008

AHK - GetGlobal()

This is a simple function for manipulating a global variable in a function that doesn't have assume-global mode on.
GetGlobal(var,newval="£NO_NEW_VAL£")
{
Global
If (!RegExMatch(var,"^[a-zA-Z0-9#_@\$\?\[]]{1,254}$"))
Return 0
If (newval == "£NO_NEW_VAL£")
Return % %Var%
Else {
%var% := newval
Return 1
}
}

Example:
FuBar = Hello World!
Message()

Message() {
MsgBox % GetGlobal("FuBar")
}

No comments: