rawr my mistake!
Printable View
rawr my mistake!
This does not work, it apparently never reaches Else when ArrayName is populated. Unfortunately, found out when a project manager noticed something wasn't working anymore. Here is the code I had to use to get the check working properly:
You can replace String data type with variant or whatever data type you are using.Code:Function EmptyStrArray(ByRef StrArray() As String) As Boolean
Dim i As Integer
On Error GoTo Return_Empty
i = UBound(StrArray)
EmptyStrArray = False
Exit Function
Return_Empty:
EmptyStrArray = True
End Function
I see its your first post here, welcome to the forum.
Unfortunately you have got off to a bad start, firstly this thread is 6 years old, secondly that code does actually work (but it comes with a funny caveat)
That said welcome again and I'm glad you have fixed your bug
The fixed versions, which work for any type of array. Debug.Assert fixes buggy VB6 IDE behavior.
Version without new function:
Version as a function:Code:Dim blnInit As Boolean
blnInit = Not Not Array
Debug.Assert App.hInstance
If blnInit Then
' array is initialized
Else
' array is not initialized, "empty"
End If
Usage: If ArrayInit(Not Not YourArrayVariableHere) ThenCode:Public Function ArrayInit(ByVal NotNotArray As Long) As Boolean
Debug.Assert App.hInstance
ArrayInit = NotNotArray
End If
Background:
Not Not Array returns the pointer to safe array header, ie. the 32-bit Long value that is held by the array variable. If array is not initialized and thus does not have a safe array header, then the value is 0. In any other case the array has been initialized and it does have a safe array header.
Safe array is the structure internally used by VB6 for arrays.