Equation

Joshann

Registered User.
Local time
Today, 10:50
Joined
Mar 22, 2002
Messages
142
How do you store an arithmetic operator to a variable and still get it to behave like an arithmetic operator? I need to be able to build a long equation using only variables. I know how to do it if the arithmetic operator is constant. For example, you could do this:

varNum1 = 2
varNum2 = 3
varNum3 = 4
varResult = varNum1 + varNum2 - varNum3

The problem is that there can be any number of operators and numbers, so I need to be able to store the operators to variables too. I tried this:
varNum1 = 2
varNum2 = 3
varNum3 = 4
varOp1 = "+"
varOp2 = "-"
varResult = val(varNum1 & varOp1 & varNum2 & varOp2 & varNum3)

But, as I suspected, that doesn't work. Can anyone help?
 
The function to use is Eval():-

varResult = Eval(varNum1 & varOp1 & varNum2 & varOp2 & varNum3)
 
Thank you so much! That's exactly what I needed.
 

Users who are viewing this thread

Back
Top Bottom