• Status: Solved
• Priority: Medium
• Security: Public
• Views: 324

# Create string by calculating other strings

I have two strings.
strValue = "200.50"
strCalculation = "/5/4"

I need to get the value of strValue and strCalculation...
i.e: 200.50/5/4

Is this possible?
0
antonioking
• 2
1 Solution

Commented:
In Excel VBA, yes - you can use:
``````Evaluate(strvalue & strcalculation)
``````
0

Commented:
``````MsgBox Evaluate(strValue & strCalculation)
``````
0

Commented:
so you need the value of the expression 200.50 / 5 / 4 = 200.50 / 20 = 10.025 ?

to get the value of strValue, use : val(strValue)
to perform the calculations however depends on how far you would want to go. building a complete mathematic parser will take you a lot effort.
When the calculations are simple (eg. only dividing or multiplying), it can be done like :
``````strValue = "200.50"
strCalculation = "/5/4"

numerator = Val(strValue)
While Left(strCalculation, 1) = "/"
pos = InStr(Mid(strCalculation, 2), "/")
If pos > 0 Then
denominator = Val(Mid(strCalculation, 2, pos - 1))
Else
denominator = Val(Mid(strCalculation, 2))
End If
numerator = numerator / denominator
If pos > 0 Then
strCalculation = Mid(strCalculation, pos + 1)
Else
strCalculation = ""
End If
Wend
Result = numerator
``````
0

Commented:
hrm,

never mind ;-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.