Click here to Skip to main content
15,914,943 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i create calculator with c# all buttons work greate when i create the punct button with that code it work

C#
Button num = (Button)sender;
            if (num.Text == ".")
            {

                if (!textBox9.Text.Contains("."))
                textBox9.Text = textBox9.Text + num.Text;
                    
            }


but when i do the operation with the punct button the told me i have erreur in that code
C#
Button ops = (Button)sender;
            FIRSTNUM = Double.Parse(textBox9.Text);
            textBox9.Text = "";
            OPERATION = ops.Text;
            textBox13.Text = System.Convert.ToString(FIRSTNUM) + " " + OPERATION;
Posted
Comments
Debug and see the exact line of error. I think it is due to the double parse.

If it is formatexception, then it may be on line "FIRSTNUM = Double.Parse(textBox9.Text);"
you better debug your programme and find exactly which line this error occured..
If it is on above line then you can find why this exception came, read the documentation for Double.Parse[^] it clearly say if input is not represent a number in a valid format then you get this exception. Add few validations like empty value check and also you can use Double.TryParse Method[^] instead.
 
Share this answer
 
thanks Guys .. the probleme is was i should replace the punct by virgule

Button num = (Button)sender;
C#
if (num.Text == ",")
{

    if (!textBox9.Text.Contains(","))
    textBox9.Text = textBox9.Text + num.Text;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900