Results 1 to 7 of 7

Thread: Variable names from strings?

  1. #1

    Thread Starter
    Fanatic Member Illspirit's Avatar
    Join Date
    Mar 2001
    Location
    Blackpool, England
    Posts
    815

    Red face Variable names from strings?

    hey,

    i'm pretty sure this cant be done, but just makin sure...

    is it possible to declare and reference a variable that has a name taken from a string?

    this sort of thing...
    VB Code:
    1. Dim strString as string
    2. strString = "varVariable"
    3. Dim [B]strString[/B] as variant
    Illspirit - [email protected]

    SmartBarXP Lead Developer
    SmartBarXP - The leading desktop sidebar application for Microsoft Windows XP

  2. #2
    Frenzied Member vbgladiator's Avatar
    Join Date
    May 2001
    Posts
    1,950
    Not that I know,

    Why would you want to anyways?

  3. #3
    New Member
    Join Date
    Jan 2002
    Posts
    11
    New project of ours

    We're not releasing any public details yet... gotta make sure it'll work

    Hydrox0r


    CEO - Dev Sibwarra

  4. #4
    New Member
    Join Date
    Jan 2002
    Posts
    11
    ::: makes a Tarzan-like call for help :::

    HELLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLPPPPPPPP

    (please)

    Hydrox0r


    CEO - Dev Sibwarra

  5. #5
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,526
    You can't do that directly, but you can achieve the same effect. If you want to have a set of user-defined variables and user-defined names for them, you can do something like the following:

    Dim strUserDefinedVariable(100,2) As String

    ' Then, use strUserDefinedVariable(intVar,1) to hold the User Specified variable name,
    ' And use strUserDefinedVariable(intVar,2) to hold the corresponding value for that User Specified variable name.

    I've used this technique when writing my own script file or command file interpreter programs. It allows the user to make up and use his own variable names (and corresponding values for them), while I can store and keep track of them so they can be referenced as needed.

  6. #6
    Addicted Member
    Join Date
    Aug 2001
    Posts
    158
    Now this if going back a bit but ...



    I rember from various other languages I have used in the past there is a function - normaly called something like eval - that does this sort of thing.

    Everso

  7. #7
    New Member
    Join Date
    Jan 2002
    Posts
    11
    Hmm... can't find anything like that in VB... it's kinda an object orientated thing I'm trying to do - like:

    (this doesn't work)

    Dim strVar
    strVar = "testing"

    Dim strVar as New Form1
    (need a variable named as the contents of the strVar variable)

    so the finished product would be a new instance of Form1 referenced by the variable "testing".


    CEO - Dev Sibwarra

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width