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
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Forum statistics

Threads
1,215,767
Messages
6,126,775
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top