Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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!
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,588
Default 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!



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 23
Default 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!


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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!



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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!



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default 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!


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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!



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
logical test, array, text and numbers Dan M. Excel Worksheet Functions 1 April 25th 06 08:56 AM
Test for Single Character That is in an Array scallyte Excel Worksheet Functions 2 November 11th 04 04:47 PM
Trying To Store Shapes/Objects to an array ?? Tom Ogilvy Excel Programming 2 September 21st 04 09:49 PM
Trying To Store Shapes/Objects to an array ?? Dan Thompson Excel Programming 0 September 21st 04 08:37 PM
How can you make an array of objects? ynotravid Excel Programming 7 August 28th 04 10:19 PM


All times are GMT +1. The time now is 02:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"