473,506 Members | 16,201 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Nov 14 '06 #1
4 7339
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 ***
Nov 14 '06 #2
.... but even with a collection you can't find the index of an item without
looping through the collection.

--

Terry Kreft
"Rich P" <rp*****@aol.comwrote in message
news:45***********************@news.qwest.net...
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 ***

Nov 14 '06 #3
mi********@gmail.com wrote:
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?

Nov 15 '06 #4
On 14 Nov 2006 12:51:56 -0800, mi********@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.

>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
Nov 15 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
5156
by: lawrence | last post by:
I wanted to test xml_parse_into_struct() so I took the example off of www.php.net and put this code up on a site: <?php $simple = <<<END <item>
7
3193
by: Magnus Warker | last post by:
Hi, I want to traverse an (associative) array, starting from its current position, until a certain element is reached. Then, in certain cases, I want to be able to reset the current position of...
3
2649
by: dam_fool_2003 | last post by:
Hai, For a notes in web is saw the following lines: Accessing an item at an arbitrary position: If the items in the sequence are numbered 0, 1, ... and we know the address in memory of the first...
2
6839
by: melanieab | last post by:
Hi, I'm trying to store all of my data into one file (there're about 140 things to keep track of). I have no problem reading a specific string from the array file, but I wasn't sure how to...
5
1503
by: Dan | last post by:
I wonder if anyone has suggestions for reducing the amount of time it would take to search my array using the function that I have written. I want to find a position in the array of an item that...
4
3590
by: Antoine | last post by:
Herfried and Cor:- I used tracing and actually tracked down the code that was causing the problem most likely. I wonder if you wanted to comment on it. Also I wonder if there is a better way...
3
3563
by: Ant | last post by:
Hi, I'm using an array list as the collection for my indexer (_alPeople). When i try to set _alpeople to a value at a certain index, I get an error. I can't simply add the value as it needs to be...
23
7366
by: sandy | last post by:
I need (okay, I want) to make a dynamic array of my class 'Directory', within my class Directory (Can you already smell disaster?) Each Directory can have subdirectories so I thought to put these...
2
1555
by: BurnTard | last post by:
I've been given the task to make a hangman like program, and it seemed simple to me, but I just can't make the code behave like I want it to. I need the code to check if the array "placement" is a...
0
7105
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.