0

Possible Duplicate:
How do I determine if an array is initialized in VB6?
How do I check for an object being Nothing in VB6?

In a situation where a function is returning a dynamic array as result, there is the possibility that the dynamic array was not initialized (For example, error in the execution). Is it possible to check this situation?

Function IsNothing() is not working, and UBound() is creating an error in this case.

For example:

Function find(results() As String)

    [Definition here...]

End Function

[...]

Dim results() As String
find(results)
If UBound(results) > 0 Then '<-- This line will fail when results was not defined

[...]

Thanks in advance!

Community
  • 1
  • 1
Daniel Rodríguez
  • 548
  • 1
  • 10
  • 30

1 Answers1

1

I ran into this same problem and was unable to find a clean way to do this. I ended up creating my own function to that implements a Ubound wrapped with an error handler. If it fails, I return a -1.

Private Function custom_UBound(ByRef ToTest() As String)
    On Error GoTo errHandler

    custUBound = UBound(ToTest)

    Exit Function
errHandler:
    custUBound = -1
End Function
UnhandledExcepSean
  • 12,504
  • 2
  • 35
  • 51
  • There ate several other ways to do this, see [the duplicate question](http://stackoverflow.com/questions/5340881/how-do-i-check-for-an-object-being-nothing-in-vb6) – MarkJ May 07 '12 at 17:33
  • Thank looks perfect for me, thanks! And sorry, I just saw the other questions related. I did not find them at first. – Daniel Rodríguez May 08 '12 at 07:22