Solved

Create string by calculating other strings

Posted on 2011-03-15
4
280 Views
Last Modified: 2012-05-11
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
Comment
Question by:antonioking
  • 2
4 Comments
 
LVL 85

Accepted Solution

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

Open in new window

0
 
LVL 24

Expert Comment

by:StephenJR
ID: 35139401
MsgBox Evaluate(strValue & strCalculation)

Open in new window

0
 
LVL 19

Expert Comment

by:akoster
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

Open in new window

0
 
LVL 19

Expert Comment

by:akoster
ID: 35139483
hrm,

never mind ;-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now