ShatterCoder wrote: ↑07 Oct 2022, 17:31
or if you prefer a dictionary style approach to the array:
Code: Select all
MyArray := {"AppTitle" : "MyApp", "ConfigTitle" : "Xyz", "FormatTitle" : "something", "DBViewTitle" : "Something Else"} ;setting it directly
;or
AppTitle := "MyApp"
ConfigTitle := "Xyz"
FormatTitle := "something"
MyArray := {}
MyArray["AppTitle"] := AppTitle
MyArray["ConfigTitle"] := ConfigTitle
MyArray["FormatTitle"] := FormatTitle
MyArray["DBViewTitle"] := "Something Else"
for key_var, value_var in MyArray
{
msgbox, % "the value of " key_var " is: " value_var
}
I don't think this is it either... but it's not clear as I don't understand it entirely.
I believe you are still putting values into an array, not variable names.
The distinction is: Looping through an collection of VALUES (which you're storing in an array), vs looping through a collection of VARIABLES (which I'm not sure how to collect them).
To better understand, say we had code thus:
Code: Select all
if(WinExist(AppTitle)){ ;check if appearance window is opened, then close it
Winclose, %AppTitle%
}
if(WinExist(ConfigTitle)){ ;check if configuration window is opened, then close it
Winclose, %ConfigTitle%
}
if(WinExist(FormatTitle)){ ;check if Format Browser window is opened, then close it
Winclose, %FormatTitle%
}
if(WinExist(DBViewTitle)){ ;check if database view window is opened, then close it
Winclose, %DBViewTitle%
}
if(WinExist(LogOnTitle)){ ;check if Format Browser window is opened, then close it
Winclose, %LogOnTitle%
}
if(WinExist(EraseTitle)){ ;check if File Erase window is opened, then close it
Winclose, %EraseTitle%
}
if(WinExist(NewTitle)){ ;check if File Erase window is opened, then close it
Winclose, %NewTitle%
}
if(WinExist(OpenFile)){ ;check if File Erase window is opened, then close it
Winclose, %OpenFile%
}
Another requirement is that you can not alter the form of the variable.
How would you shorten this in a loop form so that WinExist and WinClose appear only once?
Hope this example helps...
R