Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / August 2006

Tip: Looking for answers? Try searching our database.

generating a count of items in an array

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
muyBN - 01 Aug 2006 09:11 GMT
I have an array (shown below as "varArr") in which a macro searches for terms
in the array ("text1", etc.) with a while statement. I occasionally add or
delete a term from the array. Is there any way of using UBound or something
else, to pick up the quantity of terms to be used in the array, so that I can
use a variable for that quantity instead of hard-coding it each time I add or
delete a term from the list?

varArr = Array("text1", "text2", "text3", "text4")
While intCnt < 5
~~

Signature

Bryan

Jezebel - 01 Aug 2006 09:41 GMT
For intCnt = lBound(varArr) to uBound(varArr)
   ...
or

intCnt = lBound(varArr)
Do
   ..
Loop until intCnt > uBound(varArr)

Don't use For ... Next if you add or remove items within the loop.

If you do a lot of this sort of thing, you might find it easier to work with
a collection.

>I have an array (shown below as "varArr") in which a macro searches for
>terms
[quoted text clipped - 10 lines]
> While intCnt < 5
> ~~
Michael Bednarek - 02 Aug 2006 13:57 GMT
>I have an array (shown below as "varArr") in which a macro searches for terms
>in the array ("text1", etc.) with a while statement. I occasionally add or
[quoted text clipped - 6 lines]
>While intCnt < 5
>~~

Your code fragment is very terse to allow deduction of what you want to
do. However, in addtion to Jezebel's example of how to use
LBound/UBound, you can also try this construct:

 Dim varElement as Variant
 For Each varElement In varArray
   Debug.Print varElement
 Next varElement

Signature

Michael Bednarek   http://mbednarek.com/   "POST NO BILLS"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.