0

I do not want to use arrays but want to concanate variable in order to devide some variables with one loop for example something like this:

Dim varr1,varr2,varr3,varr4,i
i=1
varr1=2
varr2=5
varr3=8
varr4=9
Do While i < 5
  varr&i = (varr&i)/2
  i = i + 1
Loop

Could this be done in any way?

1
  • Even if it can be done: don't. It's a terrible practice with no redeeming qualities. Use an array or a dictionary instead. DO NOT construct variable names dynamically. EVER. Commented Aug 17, 2017 at 22:26

2 Answers 2

0

We can use the Execute command to get what you need.

Dim varr1,varr2,varr3,varr4,i
i=1
varr1=2
varr2=5
varr3=8
varr4=9
Do While i < 5
  Execute "varr"&i&" = (varr"&i&")/2"
  'Execute "MsgBox varr"&i                                'un-comment this line to see the desired output
  i = i + 1
Loop
Sign up to request clarification or add additional context in comments.

Comments

0
Dim concat
concat = varr1&varr2&varr3&varr4

You cannot automatically iterate through each of these variables unless you store them in an array.

1 Comment

We can do it using Execute statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.