I am passing a dynamic array to a function that is optional.
I need to check to see if in fact there are values in the passed array.
I have tried using IsEmpty() and IsNull (returns false on an empty array), Is Nothing (gives Type Mismatch on compile) etc but can’t seem to lick this one.
I can of course just perform an operation and trap error “200” - attempt to access an uninitialized array, but would like to know if I can test for that condition before actually triggering the error.
As Ceasar mentioned, performing an operation such as a ubound can trigger error 200 which lets you know that the array wasn’t initialized. In the end I just created a function to handle this so the error would stay clean. Here’s the code in case anyone else ever finds it useful.
Unfortunately, I need to know the type at the time of passing the array. Trying to pass it to a variant will trigger another error altogether. So, if you want to test different types of Arrays, (string, integer, etc), you need to create a separate function for each.
Function IsUnInitializedStringArray( arrayToTest () As String ) As Boolean
IsUnInitializedStringArray = False
On Error Goto ErrorThrower
On Error 200 Goto HandleUninitializedStringError
' trying to get the ubound of an uninitialized array will cause an error 200 to trigger
Dim x As Integer
x = Ubound ( arrayToTest () )
Wouldn’t it be sufficient to define the parameter arrayToTest as Variant instead of a string array? Tpyename would still return the type of what you passed into your function, if you need that info.
Subject: LotusScript Gurus! How to Check for unitialized array?
I normally check the array’s UBounds but use an error trap because the bounds check will also fail on an uninitialized array.
IsEmpty is for variants. And IsNull will be true if you specifically set a variant to Null. Nothing is used only for objects (or variants that may be assigned to an object).