【发布时间】:2019-03-15 21:01:45
【问题描述】:
我有一个名为fillUI() 的函数,其主要目的是填充已创建的 UI。在我的原始脚本中,我需要检查 20 多个编辑控件并用内容填充它们。内容存储在一个数组中。
我面临的问题是我不知道如何“返回”带有内容的全局变量,其变量名由字符串组成。
这就像说myVar1 := "Hello World" 是原始变量。然后我用varName := "myVar1" 指向该变量,然后用varName := "foobar" 更改它,但myVar1 最后仍将是Hello World..
这样的事情可能吗?
; Start of script
#SingleInstance Force
FillUI()
Gui, Add, Edit, x12 y9 w350 h30 , %Text_1%
Gui, Add, Edit, x12 y89 w350 h30 , %Text_2%
Gui, Add, Edit, x12 y159 w350 h30 , %Text_3%
Gui, Show, w390 h278, Code testing
return
FillUI() {
words := {1:"Hello World",2:"foobar",3:"lorem ipsum"}
i := 1
while(i <= words.MaxIndex()) {
global variable_name := "Text_" i
word := words[i]
; I need to return a variable here whose variable name needs to be something like "Text_X" and whose content is %word%
; This is in order to fill the UI above
;
; Is this achievable?
variable_name := word
i++
}
}
GuiClose:
ExitApp
return
; End of script
【问题讨论】:
标签: autohotkey