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 MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting a variable name from a string

Status
Not open for further replies.

infimo

Technical User
Apr 8, 2004
22
US
Is it possible to be able to reference a variable whose name is contained in a string.

So if I have x = "Hello", then can I somehow use x to reference the variable Hello?

Thanks in advance.

Mohit
 
Not sure what you want. To keep track of named objects, I use a HashTable.

Dim MyHash As New System.Collections.Hashtable( _
New CaseInsensitiveHashCodeProvider(), _
New CaseInsensitiveComparer())
........
Dim intW As Integer
Dim sName as String
If MyHash.ContainsKey(sName) Then
intW = CType(MyHash.Item(sName), Integer)
intW += 1
MyHash.Item(sName) = intW
Else
' Got 1 of whatever
MyHash.Add(sName, 1)
End If

' Don't look for blazing speed

Forms/Controls Resizing/Tabbing
Compare Code
Generate Sort Class in VB
Check To MS)
 
Thanks JohnYingling.. I guess I did think of this but wouldn't like to go through this hassle.

I was just wondering if there is a quick method.

Thanks a lot.

Mohit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top