1

我试图用记录集中的项目填充二维数组,但我不断收到以下错误:Microsoft VBScript 运行时错误'800a0009'下标超出范围:'UBound'

我也尝试将 UBound 更改为 Ubound(ProxState,1),但这只是在“For”循环开始后的行上出现以下错误:Microsoft VBScript runtime error '800a0009' Subscript out of range

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
4

3 回答 3

2

您可以使用GetRows() 一次性分配它而不是循环。

ProxState = objRS.GetRows()

见:http ://www.asp.happycodings.com/DataAccess/code1.html

于 2013-03-28T19:21:24.030 回答
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
于 2013-03-29T08:02:18.193 回答
0

哎呀,我想我错了。道歉!以下内容不正确。确保您知道 Ubound 为您提供了许多元素,所以...如果您按如下方式更改代码...

For i = 0 To UBound(ProxState,0)-1

那么它应该工作

于 2013-03-28T23:58:21.837 回答