Class Problem

Hi, with the following code, only when the checkbox is checked will it show the rest of the values in the labels (shown at bottom). Needs to be a bool. If the checkbox is not checked it also needs to show a value.

Any ideas?

   customer = new Customer();
            int phone = 0;
            int custNum = 0;
            bool mailList = false;

            if (nameTextBox.Text ==  "")
            {
                MessageBox.Show("Invalid Name");
                return;
            }

            if (addressTextBox.Text == "")
            {
                MessageBox.Show("Invalid Address");
                return;
            }
            
            
            customer.Name = nameTextBox.Text;
            customer.Address = addressTextBox.Text;


            if (int.TryParse(phoneNumberTextBox.Text, out phone))
            {
                if (int.TryParse(customerNumberTextBox.Text, out custNum))
                {
                    customer.CustomerNumber = custNum;
                    customer.Phone = phone;

                    if (mailingListSubscribeCheckBox.Checked)
                    {
                        mailList = true;
                        mailingListValueLabel.Text = "You are subscribed";
                        return;
                    }
                    else 
                    {
                        mailList = false;
                        mailingListValueLabel.Text = "You are not subscribed";
                        return;
                    }

                }
                else
                {
                    MessageBox.Show("Invalid Customer Number");
                    return;
                }
            }


            else
            {
                MessageBox.Show("Invalid Phone Number");
                return;
            }
            nameValueLabel.Text = customer.Name;
            addressValueLabel.Text = customer.Address;
            phoneNumberValueLabel.Text = customer.Phone.ToString();
            customerNumberValueLabel.Text = customer.CustomerNumber.ToString();
            mailingListSubscribeCheckBox.Checked = customer.MailingList;

Open in new window

LVL 3
Computer GuyAsked:
Who is Participating?
 
plusone3055Commented:
change bool mailList from false to TRUE on line 4

I do not belive the code  here is complete.
I would imagine that somewhere in the code that you did not provide there is an if statement that says if bool maillist is true then display
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.