rubbernilly
Programmer
In the case of a dynamic array, if it never gets filled with data, then the statements...
...will produce an error.
How can I safely test for the ubound? I've thought about doing the following:
But that is a bit cumbersome.
Then there is the option of changing the error handling just before a variable gets assigned to the upper bound, but that can't be the best way...
Is there a better way to handle this?
Code:
Dim MyArray() as String, i as integer
i = UBound(MyArray)
...will produce an error.
How can I safely test for the ubound? I've thought about doing the following:
Code:
Dim MyArray() as String
Dim MyTest() as string
'code that could potentially fill MyArray with data
MyArray = Split(sAddressString, ";")
MyTest = MyArray
Redim preserve MyTest(0)
If MyTest(0) = "" or IsNull(MyTest(0) Then
'nothing was in MyArray
End If
But that is a bit cumbersome.
Then there is the option of changing the error handling just before a variable gets assigned to the upper bound, but that can't be the best way...
Code:
Dim MyArray() as string, i as Integer
On Error Resume Next
i = UBound(MyArray)
If i = 0 then
'myarray has no data
End if
Is there a better way to handle this?