Re: Calculator
- From: "Nicholas Paldino [.NET/C# MVP]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Thu, 7 Jul 2005 10:52:27 -0400
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]
- mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
"Rodrigo Ferreira" <rjrferreira@xxxxxxxxx> wrote in message
news:e5FwFKwgFHA.3164@xxxxxxxxxxxxxxxxxxxxxxx
>
> 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]" <mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote
> in message news:O6LZSFwgFHA.1412@xxxxxxxxxxxxxxxxxxxxxxx
>>
>> 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]
>> - mvp@xxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
>> "Rodrigo Ferreira" <rjrferreira@xxxxxxxxx> wrote in message
>> news:Om4ZXAwgFHA.3936@xxxxxxxxxxxxxxxxxxxxxxx
>>>
>>> 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?
>>>
>>>
>>>
>>
>>
>>
>
>
>
.
- Follow-Ups:
- Re: Calculator
- From: Rodrigo Ferreira
- Re: Calculator
- References:
- Calculator
- From: Rodrigo Ferreira
- Re: Calculator
- From: Nicholas Paldino [.NET/C# MVP]
- Re: Calculator
- From: Rodrigo Ferreira
- Calculator
- Prev by Date: Fatal Execution Engine Error
- Next by Date: Re: Filtering a ListBox
- Previous by thread: Re: Calculator
- Next by thread: Re: Calculator
- Index(es):
Relevant Pages
|