Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Recreate variable name in loop

Status
Not open for further replies.

dodgyone

Technical User
Jan 26, 2001
431
GB
I have a series of variables in a number sequence.

Code:
Const strTest1 = "A"
Const strTest2 = "B"
Const strTest3 = "C"

I am using a loop with a counter incrementing it. A simplistic example is shown below.

Code:
intCounter = 1
Do...
  Msgbox strTest & intCounter
  intCounter = intCounter + 1
Loop

I need to reproduce the variable name within the loop using the number of the incrementing counter. The result from the message box will be.

Code:
A
B
C

Any suggestions 'cause this is driving me bl**dy mad?!!!! Cheers...
 
Use an array instead of a load of redundant Const declarations?

C
 
I eventually decided to use an array, coded the solution then looked in here for any replies. That was the very suggestion. Thanks for taking the trouble to reply.
 
>Msgbox strTest & intCounter
[tt]Msgbox eval("strTest" & intCounter)[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top