How to test if an array of custom types is nothing

orekin

Board Regular
Joined
Jun 1, 2004
Messages
50
Hi

Say I have declared a type:

Type employee
empNum as long
Name as string
End Type

And then I have an array of the type

Dim employeeList() as employee

Now here is the problem - I have a routine that iterates through the array, and it is crashing when it tries to UBound(employeeList) and the array has not yet been assigned to.

Is there a way to check for this ? I tried "If employeeList is nothing", but that tells me 'Type Mismatch'

I also tried IsEmpty(employeeList) but that just gave me a completely confusing message ... "Only user-defined types defined in public object models can be coerced to or from a variant or passed to late-bound functions" ... ??

In the end, this is the only thing I could get to work:
Err.Clear
On Error Resume Next
i = UBound(employeeList)
If Err.Number > 0 Then
SearchCache = False
Exit Function
End If
On Error GoTo 0

TIA
Orekin
 

Some videos you may like

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college

Watch MrExcel Video

Forum statistics

Threads
1,118,084
Messages
5,570,128
Members
412,305
Latest member
Mozz
Top