Name of an Array in a function call - possible to know?
Posted: 21 Jan 2018, 15:55
An little example!
I have a function with name GetArrValue(ArrayName, Key) like this!It works! but if the "ArrName" outside the function doesn't exist, and a call to the function with that "Array name", I don't get the name of the wrong "Array name" in the function. Is it possible to show the "Array name" in the function?
i.e. If a call to the function, with an array thats not exist, like this .:This message appears .: "The Array .: does not exist..."
My wish is to get this message.: "The Array .: AllColor does not exist..."
Is it possible?
I have a function with name GetArrValue(ArrayName, Key) like this!
Code: Select all
Color := {Blue: "0x0000FF", Yellow:"0xFFFF00"}
MsgBox % " Color .: " Color.Yellow
ArrName := "Color"
ArrKey := "Yellow"
MsgBox 64, Row.: %A_LineNumber% -> %A_ScriptName%, % GetArrValue(ArrName, ArrKey)
MsgBox 64, Row.: %A_LineNumber% -> %A_ScriptName%, % GetArrValue("Color", "Green")
GetArrValue(ArrayName, Key)
{ If !IsObject(ArrayName)
{ MsgBox 64, Row.: %A_LineNumber% -> %A_ScriptName%, The Array .: %ArrayName% does not exist. `nThis program is ended!
ExitApp
}
If !%ArrayName%.HasKey(Key)
{ MsgBox 64, Row.: %A_LineNumber% -> %A_ScriptName%, The Key .: %Key% does not exist in the Array .: %ArrayName% `nThis program is ended!
ExitApp
}
Return % %ArrayName%[Key . ""]
}
i.e. If a call to the function, with an array thats not exist, like this .:
Code: Select all
Result := GetArrValue("AllColor","Blue")
My wish is to get this message.: "The Array .: AllColor does not exist..."
Is it possible?