I'm developing a user control with a textbox inside. When i write something
like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me? 9 4338
Rodrigo,
My suggestion would be to get a third party math package. Either that,
or you could parse it apart yourself, but you would have to handle all the
precidence rules yourself (not hard, but not something you should have to
do).
What you could do is create a static method dynamically, something like
this:
public static double Calc()
{
return 123 + 456.456 + 456 / 453 * 45 + 4.155;
}
And then invoke it. It is easy to create a dynamic type to do this.
However, this could cause a good amount of bloat (considering how many times
you have to do this).
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
You should write your own expression parser, which can be pretty much time
consuming
or use any existing solution, e.g http://www.adersoftware.com/?page=compilers
Look also on codeproject: http://www.codeproject.com/info/sear...d=7%2F7%2F2005
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
hi
take a look at http://www.calculator.org/rpn.html a good introduction to
reverse polish notation
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
Ok!
But in textbox the type is string! How can i pass this values to decimal in
the same order?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:O6**************@TK2MSFTNGP09.phx.gbl... Rodrigo,
My suggestion would be to get a third party math package. Either that, or you could parse it apart yourself, but you would have to handle all the precidence rules yourself (not hard, but not something you should have to do).
What you could do is create a static method dynamically, something like this:
public static double Calc() { return 123 + 456.456 + 456 / 453 * 45 + 4.155; }
And then invoke it. It is easy to create a dynamic type to do this. However, this could cause a good amount of bloat (considering how many times you have to do this).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
Rodrigo,
You can use the Convert class to convert the elements in the expression
(numbers) to various numeric types, but that means parsing it apart on your
own.
Taking that string, you could create the code that I laid out for you.
The problem with that is that it is susceptable to injection attacks (if you
create a code segment and compile and run it).
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:e5**************@TK2MSFTNGP15.phx.gbl... Ok!
But in textbox the type is string! How can i pass this values to decimal in the same order?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:O6**************@TK2MSFTNGP09.phx.gbl... Rodrigo,
My suggestion would be to get a third party math package. Either that, or you could parse it apart yourself, but you would have to handle all the precidence rules yourself (not hard, but not something you should have to do).
What you could do is create a static method dynamically, something like this:
public static double Calc() { return 123 + 456.456 + 456 / 453 * 45 + 4.155; }
And then invoke it. It is easy to create a dynamic type to do this. However, this could cause a good amount of bloat (considering how many times you have to do this).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
I know very well the precedences!!!!!!
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:%2****************@TK2MSFTNGP10.phx.gbl... hi
take a look at http://www.calculator.org/rpn.html a good introduction to reverse polish notation
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl... I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
Sorry but,
I don't understand! if you can write a few code it's better to me!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:uX**************@TK2MSFTNGP10.phx.gbl... Rodrigo,
You can use the Convert class to convert the elements in the expression (numbers) to various numeric types, but that means parsing it apart on your own.
Taking that string, you could create the code that I laid out for you. The problem with that is that it is susceptable to injection attacks (if you create a code segment and compile and run it).
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:e5**************@TK2MSFTNGP15.phx.gbl... Ok!
But in textbox the type is string! How can i pass this values to decimal in the same order?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:O6**************@TK2MSFTNGP09.phx.gbl... Rodrigo,
My suggestion would be to get a third party math package. Either that, or you could parse it apart yourself, but you would have to handle all the precidence rules yourself (not hard, but not something you should have to do).
What you could do is create a static method dynamically, something like this:
public static double Calc() { return 123 + 456.456 + 456 / 453 * 45 + 4.155; }
And then invoke it. It is easy to create a dynamic type to do this. However, this could cause a good amount of bloat (considering how many times you have to do this).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl...
I'm developing a user control with a textbox inside. When i write something like this:
123 + 456.456 + 456 / 453 * 45 + 4.155
and press ENTER, the control must have to show the result.
I don't know how to start!
Anyone can help me?
I've done something!
Thank's anyway!
Greetings,
Rodrigo Ferreira,
Portugal
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl...
Sorry but,
I don't understand! if you can write a few code it's better to me!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uX**************@TK2MSFTNGP10.phx.gbl... Rodrigo,
You can use the Convert class to convert the elements in the expression (numbers) to various numeric types, but that means parsing it apart on your own.
Taking that string, you could create the code that I laid out for you. The problem with that is that it is susceptable to injection attacks (if you create a code segment and compile and run it).
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:e5**************@TK2MSFTNGP15.phx.gbl... Ok!
But in textbox the type is string! How can i pass this values to decimal in the same order?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:O6**************@TK2MSFTNGP09.phx.gbl...
Rodrigo,
My suggestion would be to get a third party math package. Either that, or you could parse it apart yourself, but you would have to handle all the precidence rules yourself (not hard, but not something you should have to do).
What you could do is create a static method dynamically, something like this:
public static double Calc() { return 123 + 456.456 + 456 / 453 * 45 + 4.155; }
And then invoke it. It is easy to create a dynamic type to do this. However, this could cause a good amount of bloat (considering how many times you have to do this).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl... > > I'm developing a user control with a textbox inside. When i write > something like this: > > 123 + 456.456 + 456 / 453 * 45 + 4.155 > > and press ENTER, the control must have to show the result. > > I don't know how to start! > > Anyone can help me? > > >
Hi,
he meants that .NET has features that let you create a type on the fly,
like compiling a piece of code on demand. This may relieve you of parsing
the expression.
Also he mention a possible problem that the user instead of a valid numeric
expression enter a valid C# set of instructions that may have side
consequences like delete a file or so.
I suggest you to do a search as this is a regular homework for computer
sciences courses ( I do remember I had to make one ).
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message
news:e3**************@TK2MSFTNGP10.phx.gbl... Sorry but,
I don't understand! if you can write a few code it's better to me!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:uX**************@TK2MSFTNGP10.phx.gbl... Rodrigo,
You can use the Convert class to convert the elements in the expression (numbers) to various numeric types, but that means parsing it apart on your own.
Taking that string, you could create the code that I laid out for you. The problem with that is that it is susceptable to injection attacks (if you create a code segment and compile and run it).
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:e5**************@TK2MSFTNGP15.phx.gbl... Ok!
But in textbox the type is string! How can i pass this values to decimal in the same order?
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in message news:O6**************@TK2MSFTNGP09.phx.gbl...
Rodrigo,
My suggestion would be to get a third party math package. Either that, or you could parse it apart yourself, but you would have to handle all the precidence rules yourself (not hard, but not something you should have to do).
What you could do is create a static method dynamically, something like this:
public static double Calc() { return 123 + 456.456 + 456 / 453 * 45 + 4.155; }
And then invoke it. It is easy to create a dynamic type to do this. However, this could cause a good amount of bloat (considering how many times you have to do this).
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard.caspershouse.com
"Rodrigo Ferreira" <rj*********@gmail.com> wrote in message news:Om**************@tk2msftngp13.phx.gbl... > > I'm developing a user control with a textbox inside. When i write > something like this: > > 123 + 456.456 + 456 / 453 * 45 + 4.155 > > and press ENTER, the control must have to show the result. > > I don't know how to start! > > Anyone can help me? > > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: mwh |
last post by:
Hi. If you remember, I posted Expressons Help. Now I am making a
calculator with javascript. I can't get this to work:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"...
|
by: Rafael |
last post by:
Hi Everyone,
I need some help with my calculator program. I need my program to
do 2 arguments and a 3rd, but the 3rd with different operators. Any
help would be great.
Here is my code....
...
|
by: Paul |
last post by:
I want to make a simple calculator program but dont know where to get
started. This is not GUI but a simple terminal program.
It would get input like this
Enter number:
5
+
10
|
by: Art |
last post by:
Hi,
In part of my application the user may need to do a simple arithmetic
calculation in order to get the value to put in a text box. I was thinking
that it would be good if I could display the...
|
by: PieMan2004 |
last post by:
Hi, ive been looking for a solid java community to help me when im tearing out my hair :)
Basically ive constructed a GUI that has to represent the same look and functions of the typical windows...
|
by: firstcustomer |
last post by:
Hi,
Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that
someone will be able to point me to a ready-made solution to my
problem!
A friend of mine (honest!) is wanting to...
|
by: TexasNewbie |
last post by:
This was originally just a calculator without a decimal point. After I added the decimal, it now tells me invalid second number.
//GUI Calculator Program
import javax.swing.*;
import...
|
by: Deathwing |
last post by:
Hi everyone one I'm playing around with trying to make an expense calculator.
I would like it so that the user can keep enter expenses until they have no more expenses. Then I would like for the...
|
by: itsmichelle |
last post by:
This is a very primative code of a java swing calculator. I have assigned all the number buttons and the operator buttons and I can add, subtract, multiply, and divide two numbers together. However,...
|
by: mandy335 |
last post by:
public class Calculator {
private long input = 0; // current input
private long result = 0; // last input/result
private String lastOperator = ""; // keeps track of...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
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: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
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: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
| |