473,414 Members | 2,019 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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 2434
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
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
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
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
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
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
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
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
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
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
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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
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...

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.