Solved

Create string by calculating other strings

Posted on 2011-03-15
4
270 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

743 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

9 Experts available now in Live!

Get 1:1 Help Now