ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Test for end of array of objects? (https://www.excelbanter.com/excel-programming/322283-test-end-array-objects.html)

peter

Test for end of array of objects?
 

If I'm looping thru an array of objects with 'For Each',
how do I test for the last good one?

If I test for "" or 0, it says "not supported"

If I test for Nothing, it says "invalid use of object"

Thanks,
Peter.

(Excel VBA under XP)


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tim Williams

Test for end of array of objects?
 
Whatever you're iterating through probably has a "count" property, so
you could try using a counter and checking to see if you're on the
last item.

Or just keep a reference to the last object and use it once you're out
of the loop.

Tim.


"peter" wrote in message
...

If I'm looping thru an array of objects with 'For Each',
how do I test for the last good one?

If I test for "" or 0, it says "not supported"

If I test for Nothing, it says "invalid use of object"

Thanks,
Peter.

(Excel VBA under XP)


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




peter

Test for end of array of objects?
 
It doesn't have a Count, probably because it's a dynamic construct.




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Tim Williams

Test for end of array of objects?
 
Then you could iterate the objects into a variant array and loop
through that instead (checking the ubound)

Tim


"peter" wrote in message
...
It doesn't have a Count, probably because it's a dynamic construct.




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




peter

Test for end of array of objects?
 
I think the problem is doing the test of the Variant, whereever it comes
from.

Why do I have to use a Variant anyway? Shouldn't it understand if I use
the class of the contained objects?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

NickHK

Test for end of array of objects?
 
Peter,
Try it as the object and see what compile error you get.

NickHK

"peter" wrote in message
...
I think the problem is doing the test of the Variant, whereever it comes
from.

Why do I have to use a Variant anyway? Shouldn't it understand if I use
the class of the contained objects?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




NickHK

Test for end of array of objects?
 
Peter,
If it is an array, you'll LBound & UBound. No ?

NickHK

"peter" wrote in message
...
It doesn't have a Count, probably because it's a dynamic construct.




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!




Colo[_105_]

Test for end of array of objects?
 
peter,
In a loop, you may use TypeName(element)??

A sample in use.
http://puremis.net/excel/code/076.shtml

Why do I have to use a Variant anyway?

Please have a look at the For Each...Next Statement in the VBA help.
[quote]
For arrays, element can only be a Variant variable.
[unquote]


--
Regards,
Colo
http://www.puremis.net/excel/


"peter" wrote in message
...
I think the problem is doing the test of the Variant, whereever it comes
from.

Why do I have to use a Variant anyway? Shouldn't it understand if I use
the class of the contained objects?




*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Bob Phillips[_6_]

Test for end of array of objects?
 
Alternative approach. Create a collection class for the objects and build a
Count property.

--

HTH

RP
(remove nothere from the email address if mailing direct)


"peter" wrote in message
...

If I'm looping thru an array of objects with 'For Each',
how do I test for the last good one?

If I test for "" or 0, it says "not supported"

If I test for Nothing, it says "invalid use of object"

Thanks,
Peter.

(Excel VBA under XP)


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!





All times are GMT +1. The time now is 01:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com