Link to home
Start Free TrialLog in
Avatar of antonioking
antoniokingFlag for United Kingdom of Great Britain and Northern Ireland

asked on

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?
ASKER CERTIFIED SOLUTION
Avatar of Rory Archibald
Rory Archibald
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
MsgBox Evaluate(strValue & strCalculation)

Open in new window

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

Open in new window

hrm,

never mind ;-)