Important alert: (current site time 7/16/2013 3:54:52 AM EDT)
 

winzip icon

Expression Evaluator (that is - STRING CALCULATOR)

Email
Submitted on: 12/13/1999
By: Konstantin Tretyakov  
Level: Advanced
User Rating: By 6 Users
Compatibility: VB 5.0, VB 6.0
Views: 25059
(About the author)
 
     Ever wanted to have a program, that will calculate the value of a given expression? (like you give it "2*3^sin(2)+23/(2*Abs(-8.5)" and it returns the value). Well HERE IT IS - My 'EVALUATOR' class. You may search all over, noone will give you such source (at least I didn't find). :) ('Eat MY code...':) ---Also, read the README.TXT File in the Zip. Thanx!
 
winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net including:McAfee.com

 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.


Other 10 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
12/14/1999 8:52:19 AMRobert

mvervi, this would be good if you distributed a program to a user that did not have Excel.
(If this comment was disrespectful, please report it.)

 
12/14/1999 11:59:10 AMBart Hermans

Thank you very very much man!!! I've been working on such a class for a very long time now, and I must say it isn't easy!!!
(If this comment was disrespectful, please report it.)

 
12/14/1999 1:23:45 PMKonstantin

mvervi, I don't understand this logic.
1) I made this for the ALGORITHM itself.
2) Excel loads for hours...(and costs much)
3) Besides, if you make a calculator app, I will ask you: "Why do you make it - there is one in Windows" ,and so with nearly every program...
(If this comment was disrespectful, please report it.)

 
12/15/1999 3:28:51 AMJavier Martin

Hi Konstantin, Very good work!
mvervi, there are so much applications where is absolutely mandatory to have modules like this ...

Javier


(If this comment was disrespectful, please report it.)

 
12/15/1999 7:06:08 PMReb

Great job! Makes it very easy to write a scripting language. This is the most useful code I've seen in awhile.
(If this comment was disrespectful, please report it.)

 
1/2/2000 2:08:39 AMKevino

I also submitted an expression parser a while back, if anyone is interested in this. Just do a search for "3D Mathematical Plot". I have an equation solver to go along with it.
(If this comment was disrespectful, please report it.)

 
1/5/2000 4:52:49 PMPhilip Leitch

Cool code... just one little fixer upper, in the function CalcFunction, PI is stated as a number (because VB does not have a PI constant). However, it can be acurately calculated by using the arc tangent (so I am a maths buff). So, it should read:
Case "PI"
CalcFunction = 4 * Atn(1)
Cheers.... and again, cool code.
(If this comment was disrespectful, please report it.)

 
1/5/2000 5:25:22 PMKonstantin Tretyakov

Yeah, right, from the point of math it is cool to calculate the PI from ATN, but from the point of programming it will be better not to make the calculation. PI is a constant and (if I'm not mistaken) I gave it with the best precision VB can handle.

If it is not enough: PI=3.14159 26535 89793 23846 26433 83279 50288 41971 69399 37510 58209 74944 59230 78164 06286 20899 86280 34825 34211 70679...
(If this comment was disrespectful, please report it.)

 
2/10/2000 12:59:50 PMJason

Cool Code Konstantin,

This is just what I was looking for.

Jason.
(If this comment was disrespectful, please report it.)

 
5/17/2000 6:29:00 PMBrian

One problem: try this -2^2 gives -4; it should give 4

-2^2 = -2*-2 = 4

(If this comment was disrespectful, please report it.)

 
5/17/2000 7:26:46 PMkt

Brian, that's not a problem, everything is correct here. (-2)^2 is 4, but -2^2=-(2^2)=-4.
(If this comment was disrespectful, please report it.)

 
5/25/2000 9:04:50 PMVanessa

This code is great. I have been trying to find something that will convert text formulas into a result and this does it just fine. Had found others, but they didn't handle brackets. Thanks for this, it will save me a lot of time.
(If this comment was disrespectful, please report it.)

 
9/11/2001 11:47:11 AMMark Hunter

Great code! Truly useful.

One suggestion for enhancement would be to evaluate expressions like:

3x^2+2x

This can be done with the current class only with the syntax:

3*x^2+2*x

Which might not be immediately intuitive. Maybe the class could add the "*" automatically when necessary.
(If this comment was disrespectful, please report it.)

 
1/30/2002 5:36:17 PMDavid

Exactly what I was looking for! Great job, Konstantin!
(If this comment was disrespectful, please report it.)

 
5/28/2003 12:11:30 AM

Thank you, I have been lokking for some code like this for a long time, but none of the modules I tried worked. However, I was wondering if their is some way to put the result into a text box instead of in a msgbox.
(If this comment was disrespectful, please report it.)

 
6/1/2004 4:01:51 PMGuido Vrijdag

Have you ever used the Microsoft Scripting Control? With that control you can script everything (not only math expression, but complete scripts in vbscript or jscript). Yet glad to see that not everyone is as lazy as I am. Still a look at msdn for the control is really worthwhile.
(If this comment was disrespectful, please report it.)

 
6/2/2004 1:03:46 AMRilov

Brother please try this code instead of your tedious class.

for evaluating an expression

Dim test As New ScriptControl
test.Language =
(If this comment was disrespectful, please report it.)

 
6/2/2004 1:07:44 AMRilov

Dim test As New ScriptControl
test.Language = "VBScript"
MsgBox test.Eval(evaluationstring)
(If this comment was disrespectful, please report it.)

 
8/16/2006 3:36:57 AMRichard Mewett

Very nice little class. This one may be old but its good! :) *****
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.