Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
2.00/5 (3 votes)
See more:
C#
public double numOfP1, numOfP2, piecePr1, piecePr2, prSub1, prSub2, totalSub;

       private void multiplyButton_Click(object sender, EventArgs e)
       {
           if ((price1.Text == null) || (numOfPiece1.Text == null))
           {
               numOfP1 = Convert.ToDouble(numOfPiece1.Text);
               numOfP1 = 0;
               piecePr1 = Convert.ToDouble(price1.Text);
               piecePr1=0; 
           }
           
           if ((price2.Text == null) || (numOfPiece2.Text == null))
           {
               numOfP2 = Convert.ToDouble(numOfPiece2.Text);
               numOfP2 = 0; 
               piecePr2 = Convert.ToDouble(price2.Text);
               piecePr2 =0; 
           }                  

           prSub2 = piecePr2 * numOfP2;
           priceSub2.Text = prSub2.ToString();
           prSub1 = piecePr1 * numOfP1;
           priceSub1.Text = prSub1.ToString();
       }
   }



I got numOfP1, piecePr1, numOfP2,piecePr2 turn to 0. They are not appear as the number I enter into these textboxes.

How can I make these textboxes appear the numbers that I typed in.

thanks,
Posted
Updated 12-Jan-12 11:31am
v2

1 solution

Apparently, they turn turn 0 because you assign "0". Look thoroughly. After all, run this code under debugger, always do. It is very simple.

By the way, you are coding wrong way in principle. You tend to use variable (members) for temporary values like numOfP1, numOfP2, piecePr1, piecePr2, prSub1, prSub2, totalSub. Everything like that should be local; what you do in invitation for bugs and useless allocation of memory.

—SA
 
Share this answer
 
v3
Comments
wizardzz 25-Apr-12 17:35pm    
That was an odd piece of code, but good job setting them right.
Sergey Alexandrovich Kryukov 25-Apr-12 17:38pm    
Thank you very much... :-)
--SA
Shahin Khorshidnia 25-Apr-12 20:53pm    
+5Good point
Sergey Alexandrovich Kryukov 25-Apr-12 21:11pm    
Thank you, Shahin.
--SA
Monjurul Habib 27-Apr-12 3:17am    
5!

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