Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Autohotkey 返回一个全局变量,使用字符串作为变量名_Autohotkey - Fatal编程技术网

Autohotkey 返回一个全局变量,使用字符串作为变量名

Autohotkey 返回一个全局变量,使用字符串作为变量名,autohotkey,Autohotkey,我有一个名为fillUI的函数,其主要目的是填充已创建的UI。在我的原始脚本中,我需要检查20多个编辑控件并用内容填充它们。内容存储在一个数组中 我所面临的问题是,我不知道如何返回包含内容的全局变量,其变量名由字符串组成 这就像说myVar1:=Hello World是原始变量。然后我用varName:=myVar1指向该变量,然后用varName:=foobar对其进行更改,但myVar1最终仍然是helloworld 这可能吗 ; Start of script #SingleInstanc

我有一个名为fillUI的函数,其主要目的是填充已创建的UI。在我的原始脚本中,我需要检查20多个编辑控件并用内容填充它们。内容存储在一个数组中

我所面临的问题是,我不知道如何返回包含内容的全局变量,其变量名由字符串组成

这就像说myVar1:=Hello World是原始变量。然后我用varName:=myVar1指向该变量,然后用varName:=foobar对其进行更改,但myVar1最终仍然是helloworld

这可能吗

; 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
这是一种方法。 脚本开头的global将脚本中使用的所有变量声明为global,因此仅在FillUIfunction中使用的变量将使用local声明


完美的非常感谢你!
; 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() {
    global
    local words := {1:"Hello World",2:"foobar",3:"lorem ipsum"}

    local i := 1
    while(i <= words.MaxIndex()) {


        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?
        Text_%i% := word

        i++
    }
}

GuiClose:
    ExitApp
return