Ubound, empty arrays and On Error not handling it

D

Don Starnes

I am trying to set values in a global, multidimensional array variables when
some forms open. The forms call a procedure in a module tests to see if the
arrays have values; if not, it Redims them and sets their values. The values
are used often throughout my application.

I use Ubound(array, 1) to test if the array has values. If the array has not
been Redimmed and it’s values haven’t been set, Ubound gives a “subscript out
of range†error. I test for the error with On Error Goto mylabel; at mylabel:
there is code for filling the arrays.

Often (but not always), the On Error fails to trap the error and throws the
error back to the procedure that called it, skipping the label and thus not
filling an array.

The problem seems to be how to test for values in an array (I’ve searched
this forum and everyone seems to use Ubound).

Is there a better way to do this? This must be a common need and a common
problem, but I haven’t been able to find the answer.

Thanks!
Don
 
R

Robert Morley

Expanding on David's reply, you can use either VarType(YourArray) or
IsArray(YourArray). Unfortunately, neither of these will be of any help if
you've declared your array as a specific type.

I've never had problems trapping the error that UBound generates, so I would
suggest taking another look at your code and see if you're accidentally
referring to your array "illegally" somewhere within the body of your error
handling code or if you're referring to it before your On Error statement.

If all else fails, post your code and we'll all pick through it with a
fine-tooth comb. :)


Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top