Declaring arrays

A

Alan Beban

As I mentioned, the first one below still printed False after I repasted
ct. After the modification you suggested for the second case below, the
first case then printed True.

Alan Beban
 
H

Harlan Grove

As I mentioned, the first one below still printed False after I repasted
ct. After the modification you suggested for the second case below, the
first case then printed True.
...

While I tested the first case, I did so in XL8/97, so under a different VBA
version. It does fail in XL8/97. I'll check under XL2K when I get home. It'd be
very odd if XL2K/VBA6 doesn't throw an error when attempting to set a range
reference to a simple value.
 
H

Harlan Grove

Harlan Grove said:
While I tested the first case, I did so in XL8/97, so under a
different VBA version. It does fail in XL8/97. I'll check under
XL2K when I get home. It'd be very odd if XL2K/VBA6 doesn't
throw an error when attempting to set a range reference to a
simple value.

It's not that. Excel is stranger than fiction sometimes. Pass an unsized
dynamic array of objects to another procedure as a variant argument, and
Excel 2000/VBA 6 treats the passed array of object references as having
LBound 0 and UBound -1. How silly of me not to have realized this.

Anyway, it looks like another revision is needed. Replace

ub1 = UBound(b, 1)
ct = (Err.Number <> 9) 'only subscript out of range error

with

ub1 = UBound(b, 1) - LBound(b, 1)
ct = (Err.Number <> 9 Or ub1 < 0) 'only subscript out of range error
 
Top