Variable Variables in Visual Basic

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BaKo
    New Member
    • Sep 2007
    • 11

    #1

    Variable Variables in Visual Basic

    Hey. I was wondering how I would be able to make a variable that has a name that contains another variable. I want to create a bunch of tabpages for files that have names that are like tab_filename. I know in php you could do ${$var} = "data";
    How would i go about this in vb? thanks
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    If we're talking strings, you can say:

    [CODE=vb]

    Dim MyVariable, MyMethod

    MyVariable = Doolittle

    MyMethod = ...
    ...

    If Doolittle Like "Lalala" Then

    This or that

    End If

    ...

    [/CODE]

    Please stay tuned, give other experts some time to see this, provide some added examples for you.

    Get a load of this site while you wait: http://functionx.com/vb/Lesson04.htm

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      One possibility might be to store them in a collection, which allows you to use a string as the index to retrieve them. So for instance you could access something in the TabName collection by referencing TabName(FileNam e).

      Comment

      • BaKo
        New Member
        • Sep 2007
        • 11

        #4
        Thanks, that solves the tabpage problem, but I also need to create whole new tabControls for each file, and I can't use a collection of tabControls, just pages. Any ideas? Is there a way to increment variable names maybe? Thanks alot!

        Comment

        • Killer42
          Recognized Expert Expert
          • Oct 2006
          • 8429

          #5
          Originally posted by BaKo
          Thanks, that solves the tabpage problem, but I also need to create whole new tabControls for each file, and I can't use a collection of tabControls, just pages. Any ideas? Is there a way to increment variable names maybe? Thanks alot!
          Hm... apart from arrays, the only way I can think of to "increment variable names" would be to use something like the Microsoft Script Control and try to build code dynamically at runtime and execute it. I don't have any experience with this, but it has been mentioned once or twice in earlier threads - you could try some searching.

          If so, also try searching on Microsoft Scripting Runtime (although that's also used for the FileSystemObjec t model, and will show up much more frequently).

          Comment

          Working...