获得对本机 VBScript 数组的引用的唯一方法是调用 Sub/Function:
>> Sub assignArray(a, i, e)
>> a(i) = e
>> End Sub
>> array1 = Array("elem1", "elem2", "elem3")
>> array2 = Array("item1", "item2", "item3")
>> WScript.Echo "array1", Join(array1), "array2", Join(array2)
>> assignArray array1, 0, "abra"
>> assignArray array2, 0, "cadabra"
>> WScript.Echo "array1", Join(array1), "array2", Join(array2)
>>
array1 elem1 elem2 elem3 array2 item1 item2 item3
array1 abra elem2 elem3 array2 cadabra item2 item3
如果那不能解决您的实际问题-顺便说一句:您的实际问题是什么?- 考虑改用对象(字典、System.Collections.ArrayList)。
拼写出来:
数组分配副本。只能通过参数传递来引用(本机)数组。由于 VBscript 既不是 C 也不是 Java,因此您必须使您的“设计”适应该语言 - 例如:
Option Explicit
Sub assignArray(a, i, e)
a(i) = e
End Sub
Randomize
Dim a1 : a1 = Split("I don't believe this")
Dim a2 : a2 = Split("solves any real-word problem")
WScript.Echo "a1:", Join(a1)
WScript.Echo "a2:", Join(a2)
If Rnd < 0.5 Then
assignArray a1, 0, "We"
Else
assignArray a2, 3, "problems"
End If
WScript.Echo "a1:", Join(a1)
WScript.Echo "a2:", Join(a2)
输出:
a1: I don't believe this
a2: solves any real-word problem
a1: We don't believe this
a2: solves any real-word problem
a1: I don't believe this
a2: solves any real-word problem
a1: I don't believe this
a2: solves any real-word problems