变量系列名称

时间:2015-10-09 00:56:10

标签: autohotkey

在AHK脚本中:

为一个变量找到上述大量变量之间的值的代码:

If (Variable1 = "sin (90°)")
    MsgBox Value is reached

如何通过此方法在名称中具有不同数字值的一系列变量之间进行搜索?从Variable5到Variable15,Variable51到Variable105等。

如果数字从5到15,51到105或74到117等,如何修改此代码?

number = 5
If (Variable%number% = "sin (90°)")
    .............

%变量%number %%是否可接受并且肯定会有效吗?

这里也可能是有用的关联阵列。什么是简单的例子?

3 个答案:

答案 0 :(得分:1)

这里的最佳做法可能是首先使用数组。

myArray := []
myArray[1] := "bla"
myArray.Push("bla2") ;by using this you don't need to worry about the index number
myArray[3] := "sin (90°)"
myArray[4] := 63456

Loop % myArray.MaxIndex() 
{
    If (myArray[A_Index] = "sin (90°)")
    {
        MsgBox Value is reached
    }
}

......另一个例子

anotherArray := []

Loop, read, C:\Files\prog.txt
{
    If (A_LoopReadLine = "FileRead, OutputVar, C:\Files\prog1.txt")
    {
        anotherArray.Push(A_LoopReadLine)
        MsgBox, An interesting code line was found. And was added to the array.
    }
    Else If (A_LoopReadLine = "blablabla")
    {
        anotherArray.Push(A_LoopReadLine)
        MsgBox, An interesting code line was found. And was added to the array.
    }
    Else If (A_LoopReadLine = "some other text line")
    {
        anotherArray.Push(A_LoopReadLine)
        MsgBox, An interesting code line was found. And was added to the array.
    } 
    ;Else
    ;{
    ;    MsgBox, Nothing important was found.
    ;}
}

Loop % anotherArray.MaxIndex() 
{
    currentArrayEntry := anotherArray[A_Index]
    MsgBox, %currentArrayEntry%
}

答案 1 :(得分:0)

表达式中,您可以使用变量扩展来修改要使用的变量的名称:

scala> spamDataModel
Called property with f: T => Boolean
res4: spamDataModel.type = spamDataModel$@20880a03

但请考虑改用arrays

答案 2 :(得分:0)

  

%变量%数%%是否可以接受,肯定会有效吗?

不。更正确的方式

% Variable%number%

但可能有问题。

可能的方法是使用Var:= expression

Variable:= number

可能是。