在VBscript中可使用VarType函数完成这个工作。这里使用IsObject和IsArray函数代替:
For Each objItem in Application.Contents
If IsObject(Application.Contents(objItem)) Then
Response.Write “Object reference: ‘” & objItem & “’<BR>”
ElseIf IsArray(Application.Contents(objItem)) Then
Response.Write “Array: ‘” & objItem & “’ contents are:<BR>”
VarArray = Application.Contents(objItem)
‘Note: the following only works with a one-dimensional array
For intLoop = 0 To UBound(varArray)
Response.Write “ Index(“ & intLoop & “) = “ & _
VarArray(intLoop) & “<BR>”
Next
Else
Response.Write “Variable: ‘” & objItem & “’ = “ _
& Application.Contents(objItem) & “<BR>”
End If
Next
varArray = Application.Contents(objItem)
使用UBound函数可以查找出数组的大小(元素的数量),这个值可以作为遍历的终止条件:
For intLoop = 0 UBound(varArray)
这个例子是一维数组,并将只显示这样的一个数组的内容。可根据需要编辑代码以处理多维数组,例如:
For intLoop = 0 To UBound(varArray)
IntNumberOfDimensions = UBound(varArray, 1)
For intDimension = 0 To intNumberOfDimensions
Response.Write “ Index(“ & intLoop & “) = “ _
& varArray(intLoop, intDimension)
Next
Response.Write “<BR>”
Next