473,480 Members | 4,827 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calculate Formulas

Hi all,
I need to calculate Formulas.

For example:
dim strFormula as string="25*(12-6)"

I ned a DotNet Function to calculate this Formula (25*(12-6)=150):

dim dblValue as double = 150

Does anyone know how can i do this?

thanks a lot

Zsuzsa
Nov 22 '05 #1
4 2438
you could call out to a JScript.NET module that then calls the built-in
JScript function, eval().

example:

EvalUtil.jsc::
===================================
import System.Console;

package Ionic
{
class JsUtil
{
public static function Eval(expr : String) : String
{
System.Console.WriteLine("expression: {0}", expr);
var result : String = eval(expr);
System.Console.WriteLine("result: {0}", result);
return result;
}
}
}

===================================
Eval.cs::
===================================
public class Test {

public static void Main() {

string str1= "((10*80) / 100)";
Ionic.JsUtil.Eval( str1 );
string str2= "(240/80)";
Ionic.JsUtil.Eval(str2);

Ionic.JsUtil.Eval(str1 + " - " + str2);

}
}
I don't know if it is possible to call directly into the JScript.NET runtime
from {vb, C#, J#, etc} without building the wrapper in JScript.

"Gálos Zsuzsa" <ga*****@chello.hu> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to calculate Formulas.

For example:
dim strFormula as string="25*(12-6)"

I ned a DotNet Function to calculate this Formula (25*(12-6)=150):

dim dblValue as double = 150

Does anyone know how can i do this?

thanks a lot

Zsuzsa

Nov 22 '05 #2
you could call out to a JScript.NET module that then calls the built-in
JScript function, eval().

example:

EvalUtil.jsc::
===================================
import System.Console;

package Ionic
{
class JsUtil
{
public static function Eval(expr : String) : String
{
System.Console.WriteLine("expression: {0}", expr);
var result : String = eval(expr);
System.Console.WriteLine("result: {0}", result);
return result;
}
}
}

===================================
Eval.cs::
===================================
public class Test {

public static void Main() {

string str1= "((10*80) / 100)";
Ionic.JsUtil.Eval( str1 );
string str2= "(240/80)";
Ionic.JsUtil.Eval(str2);

Ionic.JsUtil.Eval(str1 + " - " + str2);

}
}
I don't know if it is possible to call directly into the JScript.NET runtime
from {vb, C#, J#, etc} without building the wrapper in JScript.

"Gálos Zsuzsa" <ga*****@chello.hu> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to calculate Formulas.

For example:
dim strFormula as string="25*(12-6)"

I ned a DotNet Function to calculate this Formula (25*(12-6)=150):

dim dblValue as double = 150

Does anyone know how can i do this?

thanks a lot

Zsuzsa

Nov 22 '05 #3

"Gálos Zsuzsa" <ga*****@chello.hu> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to calculate Formulas.

For example:
dim strFormula as string="25*(12-6)"

I ned a DotNet Function to calculate this Formula (25*(12-6)=150):

dim dblValue as double = 150

Does anyone know how can i do this?

thanks a lot

Zsuzsa

If what you're trying to accomplish, is to allow a formula to be entered as
a string, then calculate the resulting value, you're going to have to parse
the string and break it up into relevant parts, then convert the parts (as
appropriate ) to the correct numeric data types. I'd start by reading up on
"String Manipulation" in the Visual Studio .NET help, then follow that with
a read of "Convert Class" (.NET Framework Library).
Those articles should get you started.

--
Peter - [MVP - .NET Academic]
Nov 22 '05 #4

"Gálos Zsuzsa" <ga*****@chello.hu> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Hi all,
I need to calculate Formulas.

For example:
dim strFormula as string="25*(12-6)"

I ned a DotNet Function to calculate this Formula (25*(12-6)=150):

dim dblValue as double = 150

Does anyone know how can i do this?

thanks a lot

Zsuzsa

If what you're trying to accomplish, is to allow a formula to be entered as
a string, then calculate the resulting value, you're going to have to parse
the string and break it up into relevant parts, then convert the parts (as
appropriate ) to the correct numeric data types. I'd start by reading up on
"String Manipulation" in the Visual Studio .NET help, then follow that with
a read of "Convert Class" (.NET Framework Library).
Those articles should get you started.

--
Peter - [MVP - .NET Academic]
Nov 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
324
by: Gálos Zsuzsa | last post by:
Hi all, I need to calculate Formulas. For example: dim strFormula as string="25*(12-6)" I ned a DotNet Function to calculate this Formula (25*(12-6)=150): dim dblValue as double = 150
4
2215
by: Sehri | last post by:
Hi all, I have just started developing a math companion tool with VS2005 and I just ran into a problem when trying to add the description of a formula. Doed anyone know how can I add math...
2
7215
by: Dennis Myrén | last post by:
Hi. Sorry if this post might be a little off the topic, but just in case anyone knows... Given a size, a position, a start angle and a sweep angle, i want to draw a bezier curve. I will...
2
11188
by: Joe | last post by:
I need to add a trend line to a scatter plot (not automatically supported by the charting package) but I don't know how to calculate it. Is there any formulas around for calculating what the trend...
3
2780
by: Carlos Magalhaes | last post by:
Hey All, I am doing some excel automation using the excel COM. I can do most of the functions and its working well until I come across a formula. I can run a formula and insert the formula...
2
1407
by: Gálos Zsuzsa | last post by:
Hi all, I need to calculate Formulas. For example: dim strFormula as string="25*(12-6)" I ned a DotNet Function to calculate this Formula (25*(12-6)=150): dim dblValue as double = 150
5
7631
by: kux | last post by:
Hello everyone, I hope someone is out here who can help me with a simple calculation... I have a sales data base in access with monthly sales history by product. to make future predictions I...
11
1647
by: rob | last post by:
I have the following scenario. A user requests some math calculations from a server. The data and a library of basic formulas reside on the server. Now the user should be able to create more...
0
1181
by: alem | last post by:
Hi Alem: To calculate Employee work expereance in Ms-Access what shall I do b/c I tried by the following formulas bu I got three or four month different I can't get exact service year and I...
3
11765
by: gator6688 | last post by:
I have to write a program that asks for a cost-per-item, number of items purchased, and a discount rate. Then it should calculate the total cost, tax due, and amount due. I have to use the...
0
7041
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7080
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6736
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5331
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4772
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4478
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2994
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1299
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
178
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.