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

时间:2015-05-26 15:15:50

标签: arrays vbscript asp-classic

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

这是来自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

1 个答案:

答案 0 :(得分:1)

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

'把它带到Array     iArray = objRS.GetRows(i,0)
****它返回两个dementinal数组。

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返回二维数组读取此内容以获取详细信息: http://www.w3schools.com/asp/met_rs_getrows.asp

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