Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsVB SyntaxEnterprise DevelopmentDatabase AccessControlsCOMWin APICrystal ReportDeploymentGeneralGeneral 2
Related Topics
VB.NET / ASP.NETMS SQL ServerMS AccessOther Database ProductsMore Topics ...

VB Forum / General 2 / June 2006



Tip: Looking for answers? Try searching our database.

using string as Array Index

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dan - 27 Jun 2006 19:14 GMT
I was wondering if anyone knew how to use a string as an array index.
what I mean is that normally one would use a number such '5' as the
array index, and that would call a value from the array:

dim example(5) as string
example(5) = "bob"

lable1.caption = example(5)

but what I want to do is use a string as the index. So you would use a
value such as "bob" and that would call a value from the array:

dim example() as string
example('test') = "something"

label1.caption = example('test')

I can think of a number of roundabout ways to do this such as using a
two dimentional array and then searching for the passed index in one
column of the array, when it is found go to the next column and there
is your value.  Is there any other way to do this?

Any and all help is appreciated

Dan
Howard Kaikow - 27 Jun 2006 20:24 GMT
convert the string to a number when used as an index..

Signature

http://www.standards.com/; See Howard Kaikow's web site.

Steve Gerrard - 28 Jun 2006 04:18 GMT
> but what I want to do is use a string as the index. So you would use a
> value such as "bob" and that would call a value from the array:
[quoted text clipped - 3 lines]
>
> label1.caption = example('test')

How about a collection:

Dim Example As Collection
Set Example = New Collection
Example.Add "something", "test"
Label1.Caption = Example("test")
andy.vandierendonck@telenet.be - 30 Jun 2006 09:35 GMT
How to save a Collection?

Thanks
Dag Sunde - 30 Jun 2006 10:34 GMT
> How to save a Collection?
>
> Thanks

To file?

Depends on the content of the collection, and the
fileformat you require it to be saved as...

Need a lot more info...

Signature

Dag.

Steve Gerrard - 30 Jun 2006 14:57 GMT
> How to save a Collection?
>
> Thanks

As Dag said, depends on everything.

Maybe you are asking about how to go through a collection. Collections use the
For Each syntax, like this:

Dim Var As Variant

For Each Var In Example
   ' you could save Var here
   ' in your case, Var is a string
   Debug.Print Var
Next Var
Dan - 30 Jun 2006 17:08 GMT
Yes, I think a collection is exactly what I need... (I'm relatively new
to VB and never heard of it before)  Thanks for all the help
 
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



©2009 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.