Array Bounds
Is there anyway to determine if an array has been dimensioned?
UBound(arrTest()) will give <Subscript out of range> error if the array is not dimensioned.
I can always set a flag if the array is initialized but gets complicated in my application. It is do-able but just curious if there is an easier way...
Thanks,
KAL
[334 byte] By [
KAL9] at [2008-1-25]
Assuming I understand your question... If an array hasn't been dimensioned, its value should be Nothing. So you can test:
If Not arrTest Is Nothing Then
upperBound = UBound(arrTest)
End If
If that didn't answer your question, could you post a code snippet demonstrating the problem, including how arrTest is declared and/or initialized?
Even using your example I get an error:
Dim arrTest() As Integer
If Not arrTest Is Nothing Then
MsgBox "Upper bound is " & UBound(arrTest())
Else
MsgBox "arrTest() is undimensioned"
End If
I get "type mismatch" on the line: If Not arrTest is Nothing Then
KAL
I ran your code in both VS.NET 2003 and VS 2005 without issue. The expected message box displaying "arrTest() is undimensioned" is displayed. One syntax issue: UBound(arrTest()) should be UBound(arrTest).
Which version of VS are you running that is giving the error? Do you have Option Explicit On and Option Strict On?
I figured as much...thanks for your help though.
I wouldn't use the On Error method either...but I was unsure how to turn on normal error handling (Goto 0)...now I know 
KAL