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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,133
Messages
5,835,588
Members
430,368
Latest member
User800

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
Top