By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,986 Members | 2,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,986 IT Pros & Developers. It's quick & easy.

Variable Variables in Visual Basic

P: 11
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
Sep 18 '07 #1
Share this Question
Share on Google+
4 Replies


Dököll
Expert 100+
P: 2,364
If we're talking strings, you can say:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Dim MyVariable, MyMethod
  3.  
  4. MyVariable = Doolittle
  5.  
  6. MyMethod = ...
  7. ...
  8.  
  9. If Doolittle Like "Lalala" Then 
  10.  
  11.   This or that
  12.  
  13. End If
  14.  
  15. ...
  16.  
  17.  
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
Sep 18 '07 #2

Expert 5K+
P: 8,434
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(FileName).
Sep 18 '07 #3

P: 11
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!
Sep 18 '07 #4

Expert 5K+
P: 8,434
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 FileSystemObject model, and will show up much more frequently).
Sep 18 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.