经典ASP Ubound返回9使下标超出范围

时间:2010-10-25 18:40:48

标签: arrays asp-classic session-variables

很抱歉,如果已经涵盖了这一点,我在搜索中找不到任何针对此问题的内容。

我正在尝试调试经典的ASP应用程序。我需要打印会话变量,其中一个是数组。我的代码在下面,我一直在使Subscript超出范围,通常这意味着数组为空(Ubound返回-1),但在这种情况下,它将返回9.我已经尝试For i = 1 To 4和{{1结果相同。

For i = 0 To 4

修改

将代码更改为

 For Each Item In Session.Contents 
     If IsArray(Session(item)) Then 

        localArray = Session(item) 
        Response.Write "<h1>Ubound = " & Ubound(localArray) & "</h1> <br />" //getting Ubound = 9 here

        For i = 1 To Ubound(localArray)
           Response.Write "<br>&nbsp;&nbsp;" & item 
           Response.Write "(" & i & ") = " & localArray(i) 
        Next 

    Elseif IsObject(Session(item)) Then 
        Response.Write "<b>" & item & " is an object </b>" 
    Else 
        Response.Write item & " = " & Session(item) 
    End If 
    Response.Write "<br>" 
Next 

还试过

For i = LBound(localArray) To UBound(localArray)

我仍然收到错误,似乎数组可能不是单维。但是我不熟悉这个会话变量的结构或创建,有没有办法在ASP中获取数组的结构?

2 个答案:

答案 0 :(得分:3)

我能够在这里使用答案:How many dimensions in my array or get the last one来获取数组的大小。我将代码更改为:

            localArray = Session(item) 

        colStart = LBound(localArray, 1)
        colEnd = UBound(localArray, 1)
        rowStart = LBound(localArray, 2)
        rowEnd = UBound(localArray, 2)

        For row = rowStart To RowEnd
            For col = colStart To colEnd
                Response.Write localArray(col,row) & "<br />"
            Next
        Next

所以今天我在一个你知道不超出范围的数组上学习了Subscript out of range,意味着它不是一个单维数组。

答案 1 :(得分:0)

假设localArray是一维数组,请将代码更改为

For i = LBound(localArray) To Ubound(localArray)
   Response.Write "<br>&nbsp;&nbsp;" & item 
   Response.Write "(" & i & ") = " & localArray(i) 
Next