Equating a String & Integer Variable

Discussion in 'ASP .Net' started by Roger Lord, Jul 2, 2003.

  1. Roger Lord

    Roger Lord Guest

    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
    Roger Lord, Jul 2, 2003
    #1
    1. Advertising

  2. Roger Lord

    Natty Gur Guest

    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!
    Natty Gur, Jul 2, 2003
    #2
    1. Advertising

  3. Roger Lord

    Roger Lord Guest

    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" <> wrote in message
    news:...
    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!
    Roger Lord, Jul 3, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad Smallridge
    Replies:
    2
    Views:
    2,533
    Brad Smallridge
    Nov 18, 2004
  2. =?Utf-8?B?Sm9l?=

    CType(x,Integer) vs. Integer.Parse(x)

    =?Utf-8?B?Sm9l?=, Feb 6, 2006, in forum: ASP .Net
    Replies:
    7
    Views:
    5,948
    =?Utf-8?B?RGF2aWQgQW50b24=?=
    Feb 7, 2006
  3. jobs
    Replies:
    0
    Views:
    411
  4. Randy Kramer
    Replies:
    12
    Views:
    374
    Robert Klemme
    Oct 25, 2007
  5. John Reye
    Replies:
    14
    Views:
    778
    Tim Rentsch
    May 8, 2012
Loading...

Share This Page