?
Solved

Evaluate String

Posted on 2004-08-28
7
Medium Priority
?
517 Views
Last Modified: 2008-01-09
Hi.
In order to evaluate a string like "2+sin(3)" I've been using a great control called MSScript.
Unfortunately, the control can not calculate sine, cosine of big numbers of type double, also it can not calculate inverse trigonometrics like Asin(number).
I want to know if there is a method in the vb.NET library that can evaluate the string.
Do you know a free full version control that would do it better than MSScript ?

I know how to make that type of method myself, but it takes a lot of time.
[You don't need to comment about using excel or ...]
0
Comment
Question by:kouroshparsa
[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
7 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 150 total points
ID: 11924886
0
 
LVL 2

Author Comment

by:kouroshparsa
ID: 11927578
Hi.
I tried this:
http://www.codeproject.com/vb/net/math_expression_evaluator.asp
but, when I try to run it, I don't see any window designer Form, may be part of the files are missing.
I appreciate the participation, and more ideas.
0
 
LVL 2

Author Comment

by:kouroshparsa
ID: 11927630
By the way, it is C# and I do not know C# very well. As I've said, I work on VB.NET
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 4

Expert Comment

by:Daniellus83
ID: 11929491
I wanted to convert this code for you, untill I found this code (VB.NET!!):

   http://www.codeproject.com/vb/net/math_expression_evaluator.asp

I tried it with: "arctan(100)"  and as you know the arc(+infity) converges to 1/2*Pi... and the program answered correct (something like 1,56...)

btw: the code works with "arc.." in stead of "a.." (like arcsin, instead of asin). This you can easily change; search the code for:

        Case "arcsin"
               Return (Math.Asin(CDbl(args(1))))

change it into

        Case "asin"
               Return (Math.Asin(CDbl(args(1))))

etc...


This code works realy great!!
0
 
LVL 4

Assisted Solution

by:Daniellus83
Daniellus83 earned 225 total points
ID: 11929517
kouroshparsa;

sorry I saw just that you already found the same project @ codeproject.com. But you got stuck I see...

You have to do this, to use the code into your porject;

> download again the project (see my link above)
> search in the downloaded archive for the file:

      Calc.vb

>copy this to your project and include it (via the solution explorer; rightclick on you project and choose "add existing item")

> Lets say you have this string: To_Be_Evaluated = "(arctan(100) + 5) / sin(3)", you would use the calc-module this way:

        Dim To_Be_Evaluated as String   =    "(arctan(100) + 5) / sin(3)"
        Dim Result_of_evaluation as Double
        Dim Calc As New mcCalc()

        Result_of_evaluation = Calc.evaluate(To_Be_Evaluated)

-------

thats it!! Try it,.. and maybe you like it!

Daniël
0
 
LVL 8

Expert Comment

by:wguerram
ID: 11933599
At the end of this thread i posted some code.

http://www.experts-exchange.om/Programming/Programming_Languages/Dot_Net/VB_DOT_NET/Q_21109510.
html

You could modify it at run time in oder to make calculations.

Add custom methods to the class at runtime like

        "Public Function Calculate() as double" + vbCrLf + _
                "Return 2+sin(3)" + vbCrLf + _
            "End Function" + vbCrLf + _

You would have to include System.Math

"Imports System.Math" + vbCrLf + _
0
 
LVL 2

Author Comment

by:kouroshparsa
ID: 11938498
Hi Daniellus83. How is it going?
I did it the way you said and I saw the result, though when I attempt to open the designer, I get the error "The document is opened by another project"   (that is not true)...Maybe after restarting my computer it'll go away.
As I've said it is C# and I am getting into vb.NET from vb6 and don't know c# much.
You talked about Asin(a big number), I talked about sin(big number)
The program you mentioned evaluates  sin(9999999999^10) to be 9.99999999E+10  which is impossible because
 -1<sin<1  (I figured that the problem is the Math library. Microsoft claims that sin(a number as double) but if you try something like msgbox(Math.sin(9999999999^10)) you get the same result !!!). And the program does not recognize errors if you enter "2+ss(5)" which is a syntax error, you get ="2"
I'm better off using MSScript...and there are formulas to calculate asin using an available functionality like atan in MSScript.
Well, thanks a lot for participating. I wish you best luck.


Hi wguerram.
The web URL you posted is invalid and I assume what you have, does not relate.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

762 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