neilwebber
Registered User.
- Local time
- Today, 23:04
- Joined
- Aug 19, 2002
- Messages
- 35
Hello
After some searching here and elsewhere, I'm not sure that this is possible but.......
I have a set of string variables. I want to perform the same operation on each variable and return the result to the same variable name.
var1 = "xxxx"
var2 = "yyyy"
var3 = "zzzz"
For each variable I want the first 2 letters. I currently operate on each variable individually.
var1 = Left(var1,2)
var2 = Left(var2,2)
var3 = Left(var3,2)
How can I do this in a loop (much neater)? Perhaps via an array?
Trouble is, I can't get the new value assigned back to the variable name. My variable name is now a variable and it appears that this is not allowed.
In the real world I have a large number of string variables and the operation is more complex than a simple trim, which equates to lots of repetitive code if done on each variable individually.
grateful for any suggestions
N
After some searching here and elsewhere, I'm not sure that this is possible but.......
I have a set of string variables. I want to perform the same operation on each variable and return the result to the same variable name.
var1 = "xxxx"
var2 = "yyyy"
var3 = "zzzz"
For each variable I want the first 2 letters. I currently operate on each variable individually.
var1 = Left(var1,2)
var2 = Left(var2,2)
var3 = Left(var3,2)
How can I do this in a loop (much neater)? Perhaps via an array?
Code:
theAry = Array(var1,var2,var3)
i = 0
Do Until i > UBound(theAry)
theAry(i) = Left(theAry(i), 2)
'set the appropriate variable to be the new string???????
i = i + 1
Loop
In the real world I have a large number of string variables and the operation is more complex than a simple trim, which equates to lots of repetitive code if done on each variable individually.
grateful for any suggestions
N