473,388 Members | 1,220 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Equating a String & Integer Variable

I am constructing a string in my program and then trying to use
it to get the value of an integer variable whose label looks like
that string. I can't figure out how to do it. For example:

Dim aXYZ As Integer = 5
Dim myString As String
Dim myResults As Integer

myString = "aXYZ"

myResults = SomeFunction?(myString)
What I want is for myResults to equal 5 using "SomeFunction?" as
shown above. How do I do that?

In actuality, I have a large dataset (7,000 rows) where I count
the number of occurrences of approximately 100 items sprinkled
throughout the rows. I have 100 integer variables structured
similar to aXYZ in my example above. As I do my counting in the
dataset, I use the following code:

For I = 0 To cntSpring - 1
mMajor = DataSet.Tables("Spring03").Rows(I).Item("MAJOR1")
Select Case mMajor
Case "ACT" : sACT += 1
Case "AED" : sAED += 1
Case "ANP" : sANP += 1
Case "ARH" : sARH += 1
etc.
End Select
Next

....where cntSprint is the number of rows in the dataset named
"Dataset" and Spring03 is the name of one of the databases making
up the dataset.

Once I come out of the For...Next loop above, I have 100 integer
variables (e.g., sACT, sAED, etc.) that represent the
distribution of their occurrence in the dataset. In another part
of my program, I am trying to construct a string like "sACT" and
do something to it so that I get the associated integer number
that came out of the For...Next loop. I'm baffled.
Thanks
Roger

Nov 17 '05 #1
2 2546
Hi,

What about using System.Collection.HashTable. you can add to the hash
table the keys (e.g., sACT, sAED, etc.) ) and values. then you can
retrive the values by the key.

Setting :

For I = 0 To cntSpring - 1
mMajor = DataSet.Tables("Spring03").Rows(I).Item("MAJOR1")
if OHashTable.ContainsKey(mMajor)
OHashTable(mMajor) += 1
else
OHashTable.Add(mMajor,1)
end if
Next

Getting :

myString = "aXYZ"

myResults = OHashTable(myString)

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #2
Natty,

Your suggestion wasn't exactly what I had in mind; but, the
bloody thing worked! Thanks for teaching me something new.

Roger

---------------------------------------

"Natty Gur" <na***@dao2com.com> wrote in message
news:u6**************@TK2MSFTNGP11.phx.gbl...
Hi,

What about using System.Collection.HashTable. you can add to the
hash
table the keys (e.g., sACT, sAED, etc.) ) and values. then you
can
retrive the values by the key.

Setting :

For I = 0 To cntSpring - 1
mMajor = DataSet.Tables("Spring03").Rows(I).Item("MAJOR1")
if OHashTable.ContainsKey(mMajor)
OHashTable(mMajor) += 1
else
OHashTable.Add(mMajor,1)
end if
Next

Getting :

myString = "aXYZ"

myResults = OHashTable(myString)

Natty Gur, CTO
Dao2Com Ltd.
28th Baruch Hirsch st. Bnei-Brak
Israel , 51114

Phone Numbers:
Office: +972-(0)3-5786668
Fax: +972-(0)3-5703475
Mobile: +972-(0)58-888377

Know the overall picture
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 17 '05 #3

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

Similar topics

9
by: Derek Hart | last post by:
I wish to execute code from a string. The string will have a function name, which will return a string: Dim a as string a = "MyFunctionName(param1, param2)" I have seen a ton of people...
2
by: Sebek | last post by:
Hello, I'm transforming a XML document in XHTML but I have problems using sub-strings, it will be clearer with an exemple: What I have: <form...
23
by: Nascimento | last post by:
Hello, How to I do to return a string as a result of a function. I wrote the following function: char prt_tralha(int num) { int i; char tralha;
2
by: Bernard Bourée | last post by:
I have a class named "Variable" with 2 properties "Name" and "Value" and the following class to handle a collection of Variable: Public Class ColVariables Inherits CollectionBase Default Public...
7
by: barrett bonden | last post by:
Is there any way to pass parameters to a function and simply know there will get there without the silly (C like ) complexity of worring about byval and or perhaps byref ? (Why bother to...
9
by: cheng | last post by:
I was trying to figure out how & work, so I wrote the following code #include <iostream> using namespace std; void print(int &); int main() { int i = 10;
11
by: RipperT | last post by:
Don't know if this group covers web apps, but here goes. In VS 2005, I am trying to get variables to hold thier values during postback from the server. I convert a text box's user-keyed value to an...
12
by: Pascal | last post by:
hello and soory for my english here is the query :"how to split a string in a random way" I try my first shot in vb 2005 express and would like to split a number in several pieces in a random way...
1
by: kellysgirl | last post by:
Now what you are going to see posted here is both the set of instructions I was given..and the code I have written. The instructions I was given are as follows In this case, you will create...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...

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.