views:

38

answers:

2

Sorry if this has been covered, I couldn't find anything specifically to this issue in my searches.

I am trying to debug a classic ASP application. I need to print the session variables, one of which is an array. My code is below, I keep getting Subscript out of range, usually this means that the array is empty (Ubound returns -1) but in this case it's coming back as 9. I've tried For i = 1 To 4 and For i = 0 To 4 with the same results.

 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 

EDIT

Changed code to

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

Have also tried

localArray = Session(item)
Response.Write localArray(2) //since UBound returns 9 figured 2nd index should be safe

I still receive the error, it seems like the array may not be single dimension. However I am not familiar with the structure or creation of this session variable, is there a way to get the structure of an array in ASP?

A: 

Assuming that localArray is a single dimensional array, change the code to

For i = LBound(localArray) To Ubound(localArray)
   Response.Write "<br>&nbsp;&nbsp;" & item 
   Response.Write "(" & i & ") = " & localArray(i) 
Next 
shahkalpesh
Tried this method as well with no luck. I'm not sure how the array is built, as I'm debugging code I didn't write... I am thinking that my problem may be that it is not a single dimensional array. Is there any way to tell what the structure of an array is?
jon3laze
+1  A: 

I was able to use the answer here: http://stackoverflow.com/questions/273410/how-many-dimensions-in-my-array-or-get-the-last-one to obtain the size of the array. I changed my code to:

            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

So today I learned Subscript out of range on an array you know is not out of range, means that it is not a single dimensional array.

jon3laze