Skip to main content

Test to see if Array is empty

This function will test to see if an array is empty or not and will return true or false.  I added a line at the beginning of the function to make sure the err.number is 0, I had it happen that it would show an error but the error wasn't caused by the testing but by something else.

The following is an example on how to use it:

Dim myArray() as string

msgbox IsVarArrayEmpty(myArray) ' will return TRUE

Redim myArray(1)

myArray(0) = "Apple"

myArray(1) = "Pear"

msgbox IsVarArrayEmpty(myArray) ' will return FALSE

Snippet
Function IsVarArrayEmpty(anArray As Variant) As Boolean
 
	Dim i As Integer
	Err.number = 0
	On Error Resume Next
	i = UBound(anArray,1)
	If Err.number = 0 Then
		IsVarArrayEmpty = False
	Else
		IsVarArrayEmpty = True
	End If
	Err.number = 0 'reset error to 0
End Function