我正在尝试用记录集中的项填充2D数组,但是我一直收到以下错误: Microsoft VBScript运行时错误' 800a0009' 下标超出范围:' UBound'
我也尝试将UBound更改为Ubound(ProxState,1),但这只是在' For'开始后的行上给出了以下错误。环: Microsoft VBScript运行时错误' 800a0009' 下标超出范围
Dim ProxCount, LastProx
ProxCount = 0
Do While Not objRS.EOF
ProxCount = ProxCount + 1
objRS.MoveNext
Loop
LastProx = ProxCount - 1
objRS.MoveFirst
Dim ProxState
ProxState = Array(LastProx,1)
For i = 0 To UBound(ProxState,0)
ProxState(i,0) = objRS("ProximityName")
ProxState(i,1) = objRS("InState")
Next
答案 0 :(得分:2)
您可以使用GetRows()
一次性分配所有内容而不是循环播放。
ProxState = objRS.GetRows()
答案 1 :(得分:0)
还有一种方法:
Dim ProxCount
Dim ProxState()
ProxCount = 0
If (not objRS.Eof) Then
ProxCount = objRS.RecordCount
ReDim ProxState(ProxCount - 1, 1)
For i = 0 To ProxCount - 1
ProxState(i, 0) = objRS("ProximityName")
ProxState(i, 1) = objRS("InState")
Next
End If