Connecting Tech Pros Worldwide Help | Site Map

Array Index / Item position ?

 
LinkBack Thread Tools Search this Thread
  #1  
Old November 14th, 2006, 07:35 PM
midlothian@gmail.com
Guest
 
Posts: n/a
Default Array Index / Item position ?

Hello
Is there a way to get the index of an item in an array? For instance,
if I have:

MyArray = Array("NY","CT","TX","NM")

....can I see what position CT is in the array?
Thanks


  #2  
Old November 14th, 2006, 08:15 PM
Rich P
Guest
 
Posts: n/a
Default Re: Array Index / Item position ?

THe only way to get an index from an array is to loop through the array
until you match the desired value. YOu can use a collection object
which uses keys collObj.Add(value, key).

Rich

*** Sent via Developersdex http://www.developersdex.com ***
  #3  
Old November 14th, 2006, 08:25 PM
Terry Kreft
Guest
 
Posts: n/a
Default Re: Array Index / Item position ?

.... but even with a collection you can't find the index of an item without
looping through the collection.

--

Terry Kreft


"Rich P" <rpng123@aol.comwrote in message
news:455a36c1$0$10300$815e3792@news.qwest.net...
Quote:
THe only way to get an index from an array is to loop through the array
until you match the desired value. YOu can use a collection object
which uses keys collObj.Add(value, key).
>
Rich
>
*** Sent via Developersdex http://www.developersdex.com ***

  #4  
Old November 14th, 2006, 11:25 PM
Lyle Fairfield
Guest
 
Posts: n/a
Default Re: Array Index / Item position ?

midlothian@gmail.com wrote:
Quote:
Hello
Is there a way to get the index of an item in an array? For instance,
if I have:
>
MyArray = Array("NY","CT","TX","NM")
>
...can I see what position CT is in the array?
Thanks
If it were important I'd hack something up along these lines (it would
need some more work):

Dim MyArray As Variant
Dim tempString As String
MyArray = Array("NY", "CT", "TX", "NM")
tempString = "/" & Join(MyArray, "/") & "/"
Debug.Print UBound(Split(left(tempString, InStr(tempString, "/CT/")),
"/")) - 1

but ... why would it be important?

  #5  
Old November 14th, 2006, 11:35 PM
Tom van Stiphout
Guest
 
Posts: n/a
Default Re: Array Index / Item position ?

On 14 Nov 2006 12:51:56 -0800, midlothian@gmail.com wrote:

How did you get these values into this variant array? Perhaps
something can be done at the source.
If not, just loop using a For Each loop. On small arrays like this the
ugly n/2 performance is negligible.

-Tom.

Quote:
>Hello
>Is there a way to get the index of an item in an array? For instance,
>if I have:
>
>MyArray = Array("NY","CT","TX","NM")
>
>...can I see what position CT is in the array?
>Thanks
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.