Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array - How to check if array has no elements in it? 1

Status
Not open for further replies.

lollyjar

Programmer
Aug 3, 2003
29
GB
How do I check if an array has any elements in it. If I hover over an array with no elements, the pop-up box says that the value is 'nothing', but if I try to use ubound(array()), then I get a 'Subscipt out of range' error. There must be some way?

Cheers,

Lollyjar
 
I use the following function to determine if an array is empty or not:

Code:
Public Function IsEmptyArray(tArray As Variant) As Boolean
Dim lngElements As Long
    
    On Error Resume Next
    lngElements = UBound(tArray)
    
    IsEmptyArray = IIf(Err.Number = 0, False, True)
    
    Err.Clear
End Function

Just put this in a module and call within your code and you should be good to go.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top