Changing a calculated value in a label when a button is pressed in c# -


i'm relatively new programming; know basics of c , less in c#. i'm trying write program job allow user enter value, value increase or decreased contract amount. i've looked everywhere , can't find exact answer need. tried loop until read windows form loop.

the issue i'm having every time user enters second value program calculates amount original contract value, it's not keeping updated value after calculation. if writing console app figure out don't have lot of experience forms.

here code button_click:

private void button1_click(object sender, eventargs e)     {         const double contract_balance = 229481.65;         const double sub_balance = 196817.63;          double subbal = sub_balance;         double bal = contract_balance;         double enterpayment = 0;           subballabel.text = subbal.tostring("c");         balancelabel.text = bal.tostring("c");               //user input payment             enterpayment = double.parse(paycotextbox.text);              // balances             subbal = subbal + enterpayment;             bal = bal + enterpayment;               // text labels              subballabel.text = subbal.tostring("c");             balancelabel.text = bal.tostring("c");                // update balance label             subballabel.update();             balancelabel.update();                // clear text box             paycotextbox.clear(); 

your subbal , bal variables local method, means don't hold values across calls. move them out class/form level can used on time:

public partial class form1 : form {      const double contract_balance = 229481.65;     const double sub_balance = 196817.63;      double subbal = sub_balance;     double bal = contract_balance;      public form1()     {         initializecomponent();         this.load += form1_load;     }      void form1_load(object sender, eventargs e)     {         subballabel.text = subbal.tostring("c");         balancelabel.text = bal.tostring("c");     }      private void button1_click(object sender, eventargs e)     {           double enterpayment = 0;          subballabel.text = subbal.tostring("c");         balancelabel.text = bal.tostring("c");          //user input payment         enterpayment = double.parse(paycotextbox.text);          // balances         subbal = subbal + enterpayment;         bal = bal + enterpayment;          // text labels         subballabel.text = subbal.tostring("c");         balancelabel.text = bal.tostring("c");           // clear text box         paycotextbox.clear();     }  } 

Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -