How does one declare an array in VBScript?

前端 未结 2 1114
时光取名叫无心
时光取名叫无心 2021-01-05 15:46

I used this in Excel and it works fine.

dim varScreen (0 to 2) as string
varScreen(0) = \"sample 1\"
varScreen(1) = \"sample 2\"
varScreen(2) = \"sample 3\"
         


        
相关标签:
2条回答
  • 2021-01-05 16:28

    VBScript's (variables and) arrays can't be typed, so no "as Whatever". VBscript's arrays are zero-based, so no "(x To y)" but only "(z)" where z is the last index (not the size) of the array. In code:

    >> Dim varScreen(2)
    >> varScreen(0) = "sample 1"
    >> varScreen(1) = "sample 2"
    >> varScreen(2) = "sample 3"
    >> WScript.Echo Join(varScreen, "|")
    >>
    sample 1|sample 2|sample 3
    >>
    
    0 讨论(0)
  • 2021-01-05 16:48

    You can also create arrays dynamically using the Array function. Sometimes this is more convenient than assigning array elements separately.

    Dim arr
    arr = Array("sample 1", "sample2", "sample 3")
    
    0 讨论(0)
提交回复
热议问题