If I have a string variable with a formula:
string sMyformula = "3.3*5.2*5";
How can I convert this to a mathematical formula that the compiler can
calculate? For all purposes, the formula in the string will always be valid.
Thanks 5 26270
A quick and dirty solution is to use the JScript engine:
Microsoft.JScript.Vsa.VsaEngine myEngine =
Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate(
"3.3*5.2*5", myEngine
);
See also http://www.odetocode.com/Code/80.aspx for a similar
technique.
--
Scott
On Mon, 5 Jul 2004 12:45:17 -0400, "VM" <vo******@yahoo.com> wrote: If I have a string variable with a formula:
string sMyformula = "3.3*5.2*5";
How can I convert this to a mathematical formula that the compiler can calculate? For all purposes, the formula in the string will always be valid.
Thanks
--
Scott http://www.OdeToCode.com
Thanks.
Would you know if this also evaluates correct formluas with parenthesis (ie.
"(3.3*(5.2*5))+3" ) ?
Thanks again.
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:kv********************************@4ax.com... A quick and dirty solution is to use the JScript engine:
Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate( "3.3*5.2*5", myEngine );
See also http://www.odetocode.com/Code/80.aspx for a similar technique.
-- Scott
On Mon, 5 Jul 2004 12:45:17 -0400, "VM" <vo******@yahoo.com> wrote:
If I have a string variable with a formula:
string sMyformula = "3.3*5.2*5";
How can I convert this to a mathematical formula that the compiler can calculate? For all purposes, the formula in the string will always be
valid. Thanks
-- Scott http://www.OdeToCode.com
I suggest you write a postfix / prefix converter, then evaluate using Reverse Polish Notation: http://www.codeproject.com/csharp/RP...sionParser.asp
Don't let it scare you -- it is really quite easy,
Regards,
--
Matthew Cosier
Technology Support
Public Sector
Microsoft Australia Pty. Ltd.
*email:t-******@microsoft.com mob: 0401 932 250 ext:3638
"VM" wrote: Thanks.
Would you know if this also evaluates correct formluas with parenthesis (ie. "(3.3*(5.2*5))+3" ) ?
Thanks again.
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message news:kv********************************@4ax.com... A quick and dirty solution is to use the JScript engine:
Microsoft.JScript.Vsa.VsaEngine myEngine = Microsoft.JScript.Vsa.VsaEngine.CreateEngine();
return Microsoft.JScript.Eval.JScriptEvaluate( "3.3*5.2*5", myEngine );
See also http://www.odetocode.com/Code/80.aspx for a similar technique.
-- Scott
On Mon, 5 Jul 2004 12:45:17 -0400, "VM" <vo******@yahoo.com> wrote:
If I have a string variable with a formula:
string sMyformula = "3.3*5.2*5";
How can I convert this to a mathematical formula that the compiler can calculate? For all purposes, the formula in the string will always be valid. Thanks
-- Scott http://www.OdeToCode.com
Yes, I've tried parens and it works.
--s
On Mon, 5 Jul 2004 17:46:46 -0400, "VM" <vo******@yahoo.com> wrote: Thanks.
Would you know if this also evaluates correct formluas with parenthesis (ie. "(3.3*(5.2*5))+3" ) ?
Thanks again.
--
Scott http://www.OdeToCode.com This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Hal Vaughan |
last post by:
If I have a byte and I convert it to string (String sData = new
String(byte bData), then convert it back (byte bData = sData.getBytes()),
will all data be intact, or do Strings have problems with...
|
by: Jonas Prismesen |
last post by:
Hi!
I have string like this:
string expr = "123/(12*3)";
And I want to actually calculate the mathematical
expression in the string. Is there an easy way do it? Or
do I have to extract all...
|
by: rainmaker1234 |
last post by:
Its very simple in VC++. In the followeing code I have declared a
String, and a double than I am taking the string and converting it into
Double. getch() at the end is only to pause the screen so...
|
by: SiewSa |
last post by:
I have come to a situation that I need to use the result of a string
variable as a formula for performing calculation.
As an example below:
Dim X As Integer
Dim Y As Integer
Dim Result...
|
by: mdawoodk |
last post by:
i am getting error "input string was not in correct format" when
converting a string decimal into integer value.
code is like this:
string strVal = "";
int nVal = 0;
strVal = "14.9";
nVal...
|
by: jeremito |
last post by:
I am extending python with C++ and need some help. I would like to
convert a string to a mathematical function and then make this a C++
function. My C++ code would then refer to this function to...
|
by: SMichal |
last post by:
Hi, how can I parse string "? 20.000" to double ?
|
by: pankajit09 |
last post by:
Hi
I want some mechanism to validate a mathematical formula.
For eg: (a+b is not valid since the closing bracket is missing.
Please help.
|
by: clear1140 |
last post by:
Good Day!!!
Is it somehow possible to retrieve a string and then convert it into a mathematical expression? for example i have this string '14200 * 5' and then i want to convert this into a...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |