Testing array bounds safely?

G

Guest

I have an external function, not written by me, that returns a time series of
prices between two dates for a given list of stocks. If there are prices, I
am returned a 2D array containing date/price pairs. If there are no prices I
am returned a 1D array containing the string "None".

I'm having trouble testing for these conditions. The obvious test would be
to use UBound on the second dimension, but in the "no prices" case there is
no second D, and I get a bounds error. The other possibility is to test how
big the first dimension is, but zero is an appropriate answer if I pass in
one stock.

So then I just tried trapping the error, but it seems this doesn't work -- I
still get the error dialog popping up.

Anyone have a suggestion here?

Maury
 
F

Frenchie

If I understand correctly, the function returns an array (one element
per date) of either 1 D (if "None") or 2 D arrays (date/price) ?

If this is the case, you can check for each element : if LBound(Array)
= Ubound(Array) --> then it's a 1 D array, otherwise, it's a 2 D array.


But the error you describe suggest that the returned array either
contains a string value (instead of a 1 element array) or a 2 element
array. Which explains the error using Ubound when the value is "None"

If this is the case, you can use Vartype(ReturnedArray(CurrentIndex))
to see if it returns : 8 (a string value ("None")) or >= 8192, which
means it's an array.


If these scenarios do not match your situation, then I'm afraid I do
not understand correctly the structure of the array returned by the
function. Maybe can you clarify ?

HTH


Il se trouve que Maury Markowitz a formulé :
 
D

Dirk Goldgar

Maury Markowitz said:
I have an external function, not written by me, that returns a time
series of prices between two dates for a given list of stocks. If
there are prices, I am returned a 2D array containing date/price
pairs. If there are no prices I am returned a 1D array containing the
string "None".

I'm having trouble testing for these conditions. The obvious test
would be to use UBound on the second dimension, but in the "no
prices" case there is no second D, and I get a bounds error. The
other possibility is to test how big the first dimension is, but zero
is an appropriate answer if I pass in one stock.

So then I just tried trapping the error, but it seems this doesn't
work -- I still get the error dialog popping up.

Anyone have a suggestion here?

I'd probably do that by error-trapping, but see the closing message in
this thread, which gets down to the low-level innards:

http://groups.google.com/group/comp...read/thread/d3e98c1436db1563/4795e6100642da07
 

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