2015-10-19 76 views
0
public partial class Form1: Form { 
    // Define a few variables 
    int InputInteger; 
    int HoldInteger; 
    int OutputInteger; 

    public Form1() { 
     InitializeComponent(); 
    } 

    private void exitBtn_Click(object sender, EventArgs e) { 
     //Used to close the form when exit is clicked 
     this.Close(); 
    } 

    private void clearBtn_Click(object sender, EventArgs e) { 
     //this will deselect all of the radio buttons, along with clearing the 
     // textboxes with input and output information. 
     depositBtn.Checked = false; 
     checksBtn.Checked = false; 
     serviceBtn.Checked = false; 
     inputTxt.Clear(); 
     outputTxt.Clear(); 
    } 

    private void calculateBtn_Click(object sender, EventArgs e) { 

     // Calculate button actions 
     try { 
      InputInteger = Convert.ToInt32(inputTxt.Text); 
      // For each radio button checked gives an action to the calculate button 
      if (depositBtn.Checked == true); { 
       OutputInteger = (InputInteger + HoldInteger); 
       outputTxt.Text = OutputInteger.ToString(); 

      } else if (checksBtn.Checked == true); { 
       if (InputInteger > OutputInteger); { 
        OutputInteger = (HoldInteger - 10); 
        outputTxt.Text = OutputInteger.ToString(); 
        MessageBox.Show("Insufficient Funds"); 
        if (HoldInteger < 0); { 
         MessageBox.Show("Negative account balance"); 
        } 
       } else if (InputInteger <= HoldInteger); { 
        OutputInteger = (InputInteger - HoldInteger); 
        outputTxt.Text = OutputInteger.ToString(); 

       } 
      } else if (serviceBtn.Checked); { 
       if (InputInteger > OutputInteger); { 
        OutputInteger = (HoldInteger - 10); 
        outputTxt.Text = OutputInteger.ToString(); 
        MessageBox.Show("Insufficient Funds"); 
        if (HoldInteger < 0); { 
         MessageBox.Show("Negative account balance"); 
        } 
       } else if (InputInteger <= HoldInteger); { 
        OutputInteger = (InputInteger - HoldInteger); 
        outputTxt.Text = OutputInteger.ToString(); 

       } 
      } 
     } catch { 

     } 

    } 

    private void outputTxt_TextChanged(object sender, EventArgs e) { 

    } 
} 
} 

我沒有在我的只讀outputTxt文本框中獲取任何文本。任何幫助表示讚賞。我需要在計算按鈕的每次單擊事件後顯示outputTxt。我已經使用HoldInteger來保存輸出整數的中間計算,它應該是每次選擇單選按鈕的最終輸出。 My formC#程序不顯示輸出值

+0

神聖的廢話我覺得自己像一個白癡,不應該試圖寫一個分心的程序。感謝一堆dotnetom! –

回答

7

您需要從每個if聲明的末尾刪除;

變化

if (depositBtn.Checked == true) ; 

if (depositBtn.Checked == true) 

做它在你之後if語句中使用;所有地方。

這是因爲如果在if語句之後使用;,則表明您正在有效地添加一個空的腳本塊。這些代碼基本相同:

// this code block 
if (depositBtn.Checked == true); 
{ 
    OutputInteger = (InputInteger + HoldInteger); 
    outputTxt.Text = OutputInteger.ToString(); 
} 

//is identical to 
if (depositBtn.Checked == true) 
{ 
} 
{ 
    OutputInteger = (InputInteger + HoldInteger); 
    outputTxt.Text = OutputInteger.ToString(); 
} 
0

一切都很好,除了;之後if(condition); 刪除全部;就在條件語句之後。並寫如if(condition){} 然後你很好去。