2015-10-19 6 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 отображался после каждого события щелчка кнопки Calculate. Я использовал HoldInteger для проведения промежуточных вычислений для конечного результата, который должен быть конечным выходом для каждого выбора переключателя. My formC# программа не отображает выходное значение

+0

Святое дерьмо Я чувствую себя идиотом, не стоит пытаться писать программу с отвлечениями. Спасибо, куча дотнет! –

ответ

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){} , тогда вы пойдете хорошо.