對不起,如果這已被覆蓋,我找不到任何具體到我的搜索此問題。經典ASP Ubound返回9獲取下標超出範圍
我想調試一個經典的ASP應用程序。我需要打印會話變量,其中一個是數組。我的代碼如下,我不斷得到下標超出範圍,通常這意味着該數組是空的(Ubound返回-1),但在這種情況下,它回來了9.我試過For i = 1 To 4
和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> " & 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)
也曾嘗試
localArray = Session(item)
Response.Write localArray(2) //since UBound returns 9 figured 2nd index should be safe
我仍然收到錯誤,好像陣列可能不是單一維度。但是,我不熟悉此會話變量的結構或創建,有沒有辦法獲得ASP中的數組結構?
嘗試這種方法以及沒有運氣。我不確定數組是如何構建的,因爲我正在調試我沒有寫入的代碼......我想我的問題可能是它不是單維數組。有什麼方法可以說明數組的結構是什麼? – jon3laze 2010-10-25 18:50:21