Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Naming array index

Status
Not open for further replies.

mattscotney

Programmer
Jul 31, 2002
57
AU
Hi all,

Is there any way to name the array index?

example:

dim myArray(3)

myArray(0 := a)
myArray(1 := b)
myArray(2 := c)
myArray(3 := d)

Then to assign elements using the created index:

myArray(a) = "apples"
myArray(b) = "bananas"
myArray(c) = "cherries"
myArray(d) = "pears"

Any help would be greatly appreciated.

Thanks in advance,
Matt Scotney
 
you can use enumerated types....

public enum indexes '(whatever you want to name it)
a=0 'will be 0
b '1
c '2
d 'and so on
end enum


than you can just you the a,b,c,d,etc as your index....
enjoy
 
Thanks Jooky,

Will that work if I want to use 2D or 3D arrays and require completly different index's for each?

example:
dim myArray(x, y)
Different indexes for both x and y.
x index may be name, color, weight, length.
y index may be dog, cat, mouse.

Thanks again.
 
Hi mattscotney,

All that the enumeration is doing for you is defining names you can use instead of numbers; you can use them anywhere in place of those numbers - their scope is not limited to your array. You could equally well (and perhaps more obviously) have coded ..

Const a as integer = 0
Const b as integer = 1
Const c as integer = 2
Const d as integer = 3
etc.

I don't think there is any way of doing what (I think) you want which is to have names you can use as indices in your array but which have no meaning in any other context.

Enjoy,
Tony
 
Yes Tony,

I am after a way to have names I can use as the indices in an array. Anyone know how?

Thanks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top