this is the example. what if the array should be from Mynum1="1" to MyNum100="100"
MyNum1="1"
MyNum2="2"
MyNum3="3"
wat is the best way to declare this.
this is the example. what if the array should be from Mynum1="1" to MyNum100="100"
MyNum1="1"
MyNum2="2"
MyNum3="3"
wat is the best way to declare this.
要遍历其中的 100 个:
Dim myNum(99)
for i = 0 to 99
myNum(i) = i+1
next
for i = 0 to 99
wscript.echo i & " - " & myNum(i)
next
将其声明为Array
:
MyNums = Array("1", "2", "3")
您可以通过以下方式访问每一个:
foo = MyNums(1)
哪个将分配foo
给"2"
.
从技术上讲,这是可行的,但这是一种非常糟糕的做法。Execute
您可以使用以下语句执行动态创建的代码:
Dim i
for i = 1 to 100
Execute "Dim myNum" & i & " : myNum" & i & " = """ & i & """"
' Creates and executes strings like: Dim myNum1 : myNum1 = "1"
next
同样,如果有任何其他方式,请不要这样做,例如使用数组,如 DesertIvy 和 ServerGuy 向您展示的那样。