i need a better code to solve 2 problems , i had solved these problems but with a "long and dirty code"
1)case select statement with multiple expression
2)adjusting variable after each step of calculation (adjusting answer to answer1 or answer2 if condition matched)
Function calculator(step1 As Double, step2 As Double)
Dim answer1 As Double, answer2 As Double, answer As Variant
Dim a As Double, b As Double
a = 10
b = 20
If step1 = 1 Or step2 = 1 Then 'this is the code i don't want,planned to use case select statement with multi expression but don't know how
answer = Evaluate(" (" & a & ")+(" & b & ") ")
If step1 = 1 Then answer1 = answer 'this is the code i don't want, because i have many steps of calculation and methods of calculation to code
If step2 = 1 Then answer2 = answer 'this is the code i don't want, because i have many steps of calculation and methods of calculation to code
End If
If step1 = 2 Or step2 = 2 Then 'this is the code i don't want,planned to use case select statement with multi expression but don't know how
answer = Evaluate(" (" & a & ")/(" & b & ") ")
If step1 = 2 Then answer1 = answer 'this is the code i don't want, because i have many steps of calculation and methods of calculation to code
If step2 = 2 Then answer2 = answer 'this is the code i don't want, because i have many steps of calculation and methods of calculation to code
End If
calculator = answer1 + answer2
End Function
step1 and step2 are just one of the steps in the calculation but there is no priority but order of the calculation is necessary so step1 not indicated first step and step2 also,while answer1 is belong to step1 and answer2 is belong to step2,and there are 2 types of calculation, plus and divide.
if step1 = 1 ,execute a plus b,which is 10+ 20
if step2 = 1 ,execute a plus b,which is 10+ 20
if step1 = 2 ,execute a divide b,which is 10/ 20
if step2 = 2 ,execute a divide b,which is 10/ 20
because i planned to code at least 12 steps of calculation and more than 100 types of calculation,so the code above worked but very dirty and long.
i posted my expected result here:
with step1 = 1 and step2 = 2, and vice versa ,the calculator will return 30.5
for both steps = 1,return 60
for both steps = 2,return 1
Bookmarks