Solved

Create string by calculating other strings

Posted on 2011-03-15
4
311 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Arno Koster
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:Arno Koster
ID: 35139483
hrm,

never mind ;-)
0

Featured Post

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

632 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