Full Version: changing variables in a loop
UtterAccess Discussion Forums > Microsoft® Access > Access Modules
jjimmyjet
I have two variables, and want to use each in a loop. how do I return the value of the variable? such as:


var1 = 12
var2 = 15

for count = 1 to 2

tempvar = var1 'or var2 depending on the count

'do things with tempvar

next i


stringing the variable together only returns the name of the variable.
so maybe this is the first line:
tempvar = "var" & count


thanks for the help
ian
Newander5
Personally I would use an array. Something like:

Dim count as integer
Dim tempvar as integer
Dim MyVar(1 to 2) as integer
MyVar(1) = 12
MyVar(2) = 15

for count = 1 to 2
tempvar = MyVar(count)
'do stuff with tempvar
next count

HTH,
Newander
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.