1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

any ideas for calculate value in a textbox? any command

Discussion in 'C#' started by Zlebronjames, Jul 30, 2006.

  1. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    do any one know any command that take the number in the textbox to a calculation by itself?

    eg.
    imagine textbox below I type 1234+4214312
    | 1234+4214312 |

    is there any command that will calculate it?

    like this is the eg.
    variableA =(command for calcualtion) int32.parse(textbox.text);


    actually I am trying to do a short cut method if possible for a simple pluse minus div and time and also with brackets ( ) that mean do the sum (B+C) first in A(B+C) calculator. The calculation operation have to be observed. so I type out the oparation in the textbox nicely like

    textbox
    1 + 2 / 3 *(2+5)/200 - 5

    and the equal button will be coding with,

    calculate textbox = A;

    textbox.Text += string.Format("add equal sign" A);

    there is some error up here I don know how to do. cannot find ways.


    this is the way I add in the button command same goes to the number button
    Code:
    private void button12_Click(object sender, EventArgs e)
    {
    	textBox1.Text += " - ";
    }
    
    private void button13_Click(object sender, EventArgs e)
    {
    	textBox1.Text += " * ";
    }
    
    private void button14_Click(object sender, EventArgs e)
    {
    	textBox1.Text += " / ";
    }
    
    private void button16_Click(object sender, EventArgs e)
    {
    	textBox1.Text += " *( ";
    }
    
    private void button17_Click(object sender, EventArgs e)
    {
    	textBox1.Text += " ) ";
    }
    
    anyone can help me some. Sorry for the my bad english.
     
    Last edited by a moderator: Jul 31, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    I dont think there can exist any such functionality. Either you need to write it yourself or find on net something that is exactly what you are looking for.
     
  3. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    does anyone know how to use a try and catch function ? I need examples plz any C# program that has simple explain for it. Maybe I will use try and catch for calculation but I need to understand this function before I can do it.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Code:
    try
    {
        int res = 0;
        for (int i = 2; i >= 0; i--)
            res = 10 / i; // <-- Will get an exception of Divide by Zero when i = 0
    }
    catch (Exception)
    {
        System.Console.WriteLine("Caught an exception"); // Will catch the exception 
    }
     
  5. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Thanks for it but I still need more example because I don know how it really work.

    I got anyother question which is I need to know a command that is:

    if I press "(" and ")" in the textbox it will start calculate the total for sum in the brackets B+C first like eg.
    A (B+C) before it will multiply the A.

    I need command and sample for using it.

    There is any small problem with the textbox sometime got problem with the int and string stuff so I don like textbox something, but labels can slove it. maybe you got better ideal sloving it.
     
  6. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,293
    Likes Received:
    365
    Trophy Points:
    83
    Instead of that you need to be using Prefix or postfix notation. Try http://www.cs.man.ac.uk/~pjj/cs2121/fix.html as that will help you in converting any mathematical expression and evaluate that using the BODMAS Rule
     
  7. Zlebronjames

    Zlebronjames New Member

    Joined:
    Jun 14, 2006
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    I need help !!! does anyone know how to declare variable as accept 2 thing or more like number and sign like *,/ ,+, - and store it.
     
  8. manojkumarmaithil

    manojkumarmaithil New Member

    Joined:
    Jun 18, 2007
    Messages:
    14
    Likes Received:
    1
    Trophy Points:
    0
    hello try and catch blocks are use for handle exception art run time
    error are two types compile time errors nad run time errors
    when you have errors at compile time means spell mistake or any wrong statement
    and while you are not sort out that errors you are not able to run your programme. But run time error isthat when you use such command which you are not difine for example
    you difine a data in string formate and trying to calculate addition with another string or another dararype rhar is not possible and your programme will behave uncoditionaly and it teminate.but when you use try and carch block it prevent for uncoditionaly temination of programme and flash a message to user for the approriate reasone .if you want to know any other question you are mostwlcome :cool:
     
  9. rhaazy

    rhaazy New Member

    Joined:
    Jul 6, 2007
    Messages:
    28
    Likes Received:
    0
    Trophy Points:
    0
    try
    {
    some code
    }
    catch(Exception ex){System.Console.WriteLine("Exception" + ex.Message + " StackTrace: " + ex.Stacktrace);}
     

Share This Page