Results 1 to 2 of 2

Thread: Variable by name

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Variable by name

    Similar to calling a sub by name is there any such function to initialize a variable by name


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,473

    Re: Variable by name

    One way is to use a Collection since they can contain Keys which can act as a variable name. Another option would be to use Public properties in a class/form and then use CallByName, i.e.,
    Code:
    Private m_VarName As Long
    ...
    Public Property Get myVarName() As Long
        myVarName = m_VarName
    End Property
    
    ...
     MsgBox CallByName(Me, "myVarName", vbGet)
    
    ----------------------------------------------------------------------------
    Public myVarCollection As Collection
    
    Set myVarCollection = new Collection
    
    ...
       myVarCollection.Add 1234&, "myVarName" 
       MsgBox myVarCollection.Item("myVarName")
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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