Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
Solved

# Create string by calculating other strings

Posted on 2011-03-15
Medium Priority
321 Views
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
Question by:antonioking
• 2

LVL 85

Accepted Solution

Rory Archibald earned 2000 total points
ID: 35139392
In Excel VBA, yes - you can use:
``````Evaluate(strvalue & strcalculation)
``````
0

LVL 24

Expert Comment

ID: 35139401
``````MsgBox Evaluate(strValue & strCalculation)
``````
0

LVL 19

Expert Comment

ID: 35139475
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

LVL 19

Expert Comment

ID: 35139483
hrm,

never mind ;-)
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
###### Suggested Courses
Course of the Month15 days, 13 hours left to enroll