我正在尝试用 AD 组的成员填充数组。在尝试将 newArray(count) 设置为用户名时,我不断收到以下错误。
Microsoft VBScript runtime error: Subscript out of range
这是相关代码:
'set up of domain variables and stuff, verified working
Dim newArray()
Dim x
x = 0
Do While x < 1
Set objGroup = GetObject("WinNT://" & strDomain & "/" & strGroup & ",group")
count = 0
For Each objUser In objGroup.Members
newArray(count) = objUser.FullName
count = count + 1
Next
....
Your
Dim newArray()
创建一个令人厌恶的东西:一个无法增长的无大小数组,因为 UBound 失败:
>> Dim aBomination()
>> ub = UBound(aBomination)
>>
Error Number: 9
Error Description: Subscript out of range
创建大小在运行时确定的动态数组(例如 17,如果您想从没有元素的数组开始,则可能是 -1)并且 - 如果需要 - 稍后增长它的正确方法是:
>> ReDim aGood(17)
>> ub = UBound(aGood)
>> WScript.Echo ub
>> ReDim aGood(UBound(aGood) + 1)
>> aGood(UBound(aGood)) = "tail"
>> WScript.Echo UBound(aGood), aGood(UBound(aGood))
>>
17
18 tail
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)