如何在经典 asp 中使用索引获取数组字符串值

how to get array string value using index in classic asp

我需要使用索引位置值从存储在数组中的值列表中检索一个特定值。

这是来自 url 参数的位置参考:

Dim currentorder     
Dim nextorderindex
Dim rowindex 
Dim iArray
Dim i

currentorder = Trim(Request.QueryString("order"))
rowindex = CINT(Trim(Request.QueryString("rowindex")))  'e.g. let's say this is a 4

SQLOrderList = "SELECT orderno" & _
                " FROM awd_order" & _
                " WHERE order_date >= '" & dtstart & " 00:00:00'" & _
                " AND order_date < '" & dtend & " 23:59:59'" & _                    
                " ORDER BY " & sortby

objRS.Open SQLOrderList, objConn

i = objRS.RecordCount  'e.g. this contains 7 records            

If Not rowindex >= (i - 1) Then     'e.g. 4 >= (7 - 1)
    nextorderindex = (rowindex + 1) 'e.g. then nextorderindex = 5
End If

'Get recordset to Array
iArray = objRS.GetRows()   

If nextorderindex > 0 Then    'e.g. nextorderindex is 5
    response.write iArray(nextorderindex)  'e.g. here is my issue, I get: subscript out of range error
Else
    response.write currentorder
End If
Dim currentorder     
Dim nextorderindex
Dim rowindex 
Dim iArray
Dim i

currentorder = Trim(Request.QueryString("order")) // e.g. 4
rowindex = CINT(Trim(Request.QueryString("rowindex")))  '' lets say this is a 4

SQLOrderList = "SELECT orderno" & _
            " FROM _order" & _
            " WHERE CAST(FLOOR(CAST(order_date AS FLOAT)) AS DATETIME)" & _
            " BETWEEN CAST('" & dtstart & "' AS DATETIME)" & _
            " AND CAST('" & dtend & "' AS DATETIME)" & _     
            " ORDER BY " & sortby    
objRS.Open SQLOrderList, objConn

i = objRS.RecordCount  ' this contains 7 records
if i > 0 then
If Not isNumeric(rowindex) Or rowindex = "" Then 
    rowindex = 0 
End If 
If rowindex < (i) Then  ' 4 >= (7 - 1)
    nextorderindex = (rowindex + 1) ' then nextorderindex = 5
else
    nextorderindex = 0
End If

'获取这个数组 iArray = objRS.GetRows(i,0)
**** 它return两个痴呆数组。

If nextorderindex > 0 Then 'nextorderindex is 5
    response.write iArray(0,nextorderindex) ' **here is my problem, I get     subscript out of range error**
Else
    response.write currentorder
End If
end if

GetRows return二维数组详见此: http://www.w3schools.com/asp/met_rs_getrows.asp

我还没有 运行 此代码,但希望这会起作用,如果不复制错误,我会更新代码。希望这会有所帮助