PC Review


Reply
Thread Tools Rate Thread

Calculate formula from string?

 
 
Klaus Jensen
Guest
Posts: n/a
 
      9th Oct 2003
Hi!

I am currently converting an ASP/SQL Server application to VB.Net/Access.
The application performs calculations based on which products are selected.
Therefore i need to be able to store formulas in the database, replace
placeholdes with values and execute the calculation.

Earlier this was done by executing the formula on SQL Server and retrieving
the result, but that is no longer possible - or desireable for that matter.

So if I have a string that says "2*2" how to I execute this and get the
result back?

(which my sharp brain tells me should be somewhere around 4)

Thanks in advance

- Klaus


 
Reply With Quote
 
 
 
 
Nice Chap
Guest
Posts: n/a
 
      9th Oct 2003
I don't know ASP.Net but if it supports VB Script then there is a function
called 'Eval' ( and also Execute) which does exactly what you are looking
for.


"Klaus Jensen" <msnews2@icatech..dk> wrote in message
news:(E-Mail Removed)...
> Hi!
>
> I am currently converting an ASP/SQL Server application to VB.Net/Access.
> The application performs calculations based on which products are

selected.
> Therefore i need to be able to store formulas in the database, replace
> placeholdes with values and execute the calculation.
>
> Earlier this was done by executing the formula on SQL Server and

retrieving
> the result, but that is no longer possible - or desireable for that

matter.
>
> So if I have a string that says "2*2" how to I execute this and get the
> result back?
>
> (which my sharp brain tells me should be somewhere around 4)
>
> Thanks in advance
>
> - Klaus
>
>



 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      9th Oct 2003
Hi Klaus,

|| I have a string that says "2*2" ...
|| (which my sharp brain tells me should be somewhere around 4)

You know, I think you're right! Have you ever thought of going into
programming? I think you'd be good at it. ;-)

Here's one implementation of an arithmetic evaluator class.
http://www.palmbytes.de/content/dotnetlibs/mathlib.htm

The site is in German but the Download link is obvious and everything's in
English in
the zip file.The app is about showing a graph based on user-defined equations.
Have a dig around inside the evaluator. You'll probably have to do a bit of
work getting your calculator variables set up, ditto additional functions.
Then you're off!

If you want full-on calculation - anything that VB.NET can calculate - you
might like to explore the VSA Namespace. This is the realm of the scripting
engine and can handle some powerful code. Naturally it's a lot more effort to
get going. There is a newsgroup just for this topic:
microsoft.public.dotnet.vsa, though it's not hugely busy.

Another option you could explore is dynamic compilation. I haven't looked
at that myself, so my paragraph runs out here.

Out of interest, could you post some examples of the expressions that
you'd like to evaluate?

Have fun. ;-)

Regards,
Fergus


 
Reply With Quote
 
Klaus Jensen
Guest
Posts: n/a
 
      9th Oct 2003
"Fergus Cooney" <filter-(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> If you want full-on calculation - anything that VB.NET can calculate - you
> might like to explore the VSA Namespace. This is the realm of the

scripting
> engine and can handle some powerful code. Naturally it's a lot more effort

to
> get going. There is a newsgroup just for this topic:
> microsoft.public.dotnet.vsa, though it's not hugely busy.


This seems to be the best bet, also because this would possibly be a
valuable .net lesson I might be able to use later.

> Out of interest, could you post some examples of the expressions that
> you'd like to evaluate?


Well, okay then.

5,0722611E-13*x*x*x*x - 6,82931882931E-09*x*x*x +
0,0000343139083138486*x*x - 0,0762394457392556*x + 74,1895493393322

Hope your're a happy trooper now!

Thanks for your help.

- Klaus




 
Reply With Quote
 
Fergus Cooney
Guest
Posts: n/a
 
      9th Oct 2003
Hi Klaus,

Thanks for the expression. I'm trooping off to calculate it right now,
lol.

I'm interested in expression evaluators and am currently converting an old
one that I wrote for Dos. It had functions like File("C:\Foo.txt").Line(3) =
"Whatever" and RunProg ("Dir *.*").Contains (" 0 Files").

I was just wondering whether you had any functions or anything that might
give me additional food for thought.

Regards,
Fergus




 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calculate a field in Access, using a formula from a text string ALF Microsoft Access Queries 2 4th Dec 2007 05:04 AM
How to calculate the output value from a formula string??? ... Urgent Ivan Microsoft VB .NET 2 25th Feb 2005 04:27 PM
urgent question: how to calculate value with a string formula =?Utf-8?B?bWlhbyBqaWU=?= Microsoft Excel Programming 2 9th Aug 2004 12:09 PM
Re: Create a formula into a String then assign string to a cell Myrna Larson Microsoft Excel Programming 6 23rd Aug 2003 09:42 PM
Re: How can I calculate the result of a formula held in a string? Allen Browne Microsoft Access 1 16th Jul 2003 02:10 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:36 PM.