C Sharp Application error

August 8th, 2013

Hello,
I have a C Sharp application and i have 2 errors, I tried google this errors but it won’t fix it here is the first error: Cannot implicity covert type ‘string’ to ‘int’ here is the code
Source Code:
 if (tabcontrol1.SelectedIndex = "tabView")
               
            {
               
                if ((txtName.Text == "") || (txtSurname.Text == "")
                    || (txtEmail.Text == "") || (txtInterests.Text == ""))

and here is the second error:
‘System.Windows.Forms.Message’ is a ‘type’ but is used like a variable
Source Code
 MessageBox.Show = ("Please fill in the Name, Surname, Email and Interests provided\n"+
                            "in the Input Details tab page");

Answer #1
paste all your code please..
It’s a fairly common error.. it’ll just be easier to show you if you paste all your code.. (imo)
Answer #2
Try this out. I created simple form and put this on a button with the 4 text boxes you had listed. It uses an array to loop through everything instead.
I just started working with C# the last month, so I am no wiz. Hope this helps.
 private void button1_Click(object sender, EventArgs e)
        {
            string[] txtBoxes = { txtName.Text, txtSurname.Text, txtEmail.Text, txtInterests.Text };
                for (int i = 0; i < txtBoxes.Length; i++)
                {
                    string s = txtBoxes[i];
                    if (s == "")
                    {
                        MessageBox.Show("Please fill in the Name, Surname, Email and Interests provided\n" +
                            "in the Input Details tab page");
                        i++;
                        break;
                    }
                }
        }

Answer #3
You can actually take it further and set focus on the text box field that is empty. You would need to add in the code to select the tab before the txtBoxes[i].Focus(); entry to do that or just remove the focus entry. Since all your text boxes start with txt we can use TrimStart to specify the name of the field that is empty.
 private void button1_Click(object sender, EventArgs e)
        {
            TextBox[] txtBoxes = { txtName, txtSurname, txtEmail, txtInterests };
            char[] txtTrim = { 't', 'x', 't' };
                for (int i = 0; i < txtBoxes.Length; i++)
                {
                    string s = txtBoxes[i].Text;
                    if (s == "")
                    {
                        MessageBox.Show("Please fill in the " + txtBoxes[i].Name.TrimStart(txtTrim) + " field provided\n" +
                            "in the Input Details tab page");
                        txtBoxes[i].Focus();
                        i++;
                        break;
                    }
                }
        }

 

| Sitemap |