antonioking
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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 :
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
hrm,
never mind ;-)
never mind ;-)
Open in new window