473,395 Members | 1,379 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,395 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 2432
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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...
0
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
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...

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.