3
Reply

if else statements

ta mu

ta mu

Aug 16 2012 9:18 AM
1.3k
Dear

In this code on if else statements when press button if ptname or agee is empty
show mesgbox it works fine when any one of them is empty mesgbox apears but
it also save empty values mean other part of code also run.
but i want till any one of them empty control remain on them. rest of code no run
how i can do this.
 

private void button1_Click(object sender, EventArgs e)
  {
 
 
  if (ptname.Text == "")
  { MessageBox.Show("please enter a name"); }
  else if (agee.Text == "")
  {
  MessageBox.Show("please enter age");
  }
 

  int counter = int.Parse(lb26.Text);
  counter++;
  lb26.Text = counter.ToString();
  StreamWriter noo = new StreamWriter("d:\\Hospital\\hospital records.text", true);
  string nooo = lb26.Text + "  ";
  noo.Write(nooo);
  noo.Close();
 

  StreamWriter pname = new StreamWriter("d:\\Hospital\\hospital records.text", true);
  string paaname = ptname.Text + " " + " " + " " + " ";
  pname.Write(paaname);
  pname.Close();

  StreamWriter age = new StreamWriter("d:\\Hospital\\hospital records.text", true);
  string aage = agee.Text + " " + " " + " " + " ";
  age.Write(aage);
  age.Close();

  StreamWriter sex = new StreamWriter("d:\\Hospital\\hospital records.text", true);
  string se = comboBox1.SelectedItem + " " + " " + " " + " ";
  sex.Write(se);
  sex.Close();

Answers (3)