Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


use a variable in a variable

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,57815
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> use a variable in a variable
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 use a variable in a variable - 3/11/2008 11:39:54 PM   
  robszar


Posts: 182
Score: 0
Joined: 2/27/2005
From:
Status: offline
I am duplicating code and I want to see if there is a way to stop

can I use a variable in a variable?  i.e.

dim varTest_1_2
dim count

count = 0

do until count = 5
   doSomeSubRoutine(varTest_1_2_ & count)
   count = count +1
loop
 
 
Post #: 1
 
 RE: use a variable in a variable - 3/11/2008 11:45:18 PM   
  ehvbs

 

Posts: 2173
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Try:

dim sPfx : sPfx = "varTest_1_2_"
dim nCount : nCount = 0

do until nCount = 5
   doSomeSubRoutine sPfx & nCount
   nCount = nCount +1
loop
WScript.Quit 0

Sub doSomeSubRoutine( sFullName )
MsgBox sFullName
End Sub

(in reply to robszar)
 
 
Post #: 2
 
 RE: use a variable in a variable - 3/11/2008 11:45:35 PM   
  mbouchard


Posts: 1916
Score: 16
Joined: 5/15/2003
From: USA
Status: offline
If I am reading you correctly then yes, you can use a variable in a variable.  But I do not think your example would work as you are not setting Vartest_1_2 and you have an extra _ in your sub call.

If you wanted to combine varTest_1_2 and count you can do something like the below.

dim varTest_1_2
dim count

varTest_1_2 = "ABCD"
count = 0

do until count = 5
   doSomeSubRoutine(varTest_1_2 & "_"  & count)
   count = count +1
loop

_____________________________

Mike

For useful Scripting links see the Read Me First stickey!

Always remember Search is your friend.

(in reply to robszar)
 
 
Post #: 3
 
 RE: use a variable in a variable - 3/11/2008 11:55:10 PM   
  robszar


Posts: 182
Score: 0
Joined: 2/27/2005
From:
Status: offline
I want to change the variable name, not the value, sorry, should have explained that better

(in reply to mbouchard)
 
 
Post #: 4
 
 RE: use a variable in a variable - 3/12/2008 1:11:52 PM   
  DiGiTAL.SkReAM


Posts: 1183
Score: 7
Joined: 9/6/2005
From: Florida, USA
Status: offline
Try working with Execute() and ExecuteGlobal().


_____________________________

"Would you like to touch my monkey?" - Dieter (Mike Meyers)

"It is better to die like a tiger, than to live like a pussy."
-Master Wong, from Balls of Fury

(in reply to robszar)
 
 
Post #: 5
 
 RE: use a variable in a variable - 3/13/2008 12:26:33 AM   
  ebgreen


Posts: 4972
Score: 31
Joined: 7/12/2005
Status: offline
Or better yet look at dictionaries or arrays.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to DiGiTAL.SkReAM)
 
 
Post #: 6
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> use a variable in a variable Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts