+ 1

Hmmm My if statement was skipped....

So I got a function where I validating everything with flag and innerFlag as integer. First, this is a Windows Form Application write in C#, and I think there was nothing wrong with my logic, and the code return with Validation error. I can't go to Registration Success. I checked everything and I got that my flag wasn't turn 6 because the innerFlag is not even increase. Btw, forget about the picture. Hehe, I still not done with it yet :) Thanks before! private void RegisterButton_Click(object sender, EventArgs e) { int flag = 0, innerFlag = 0; if (Username_Textbox.Text != "Must use @ and .com") { flag++; } for (int i = 0; i < Username_Textbox.Text.Length; i++) { if (Username_Textbox.Text[i] == '@') { innerFlag++; } } if (Username_Textbox.Text[Username_Textbox.Text.Length - 1] == 'm') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 2] == 'o') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 3] == 'c') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 4] == '.') { innerFlag++; } if (innerFlag == 5) { flag++; } if (Username_Textbox.Text != "") { flag++; } if (Password_Textbox.Text != "") { flag++; } if (Confirm_Password.Text == Password_Textbox.Text && Confirm_Password.Text != "") { flag++; } if (Image_Name.Text != "Must jpg or pn

13th Jun 2018, 5:23 PM
Yosua Kristianto
Yosua Kristianto - avatar
5 Answers
+ 2
Yosua I ran your code with a proper username and I got "Registration Success!" I ran it without a properly formatted username and got "Please check the condition!!!....." Of course the password and confirm password was the same on both counts. You should run it in debug mode and set up break stops on the innerFlag if statements.
13th Jun 2018, 7:32 PM
ODLNT
ODLNT - avatar
+ 1
Yosua Is this all your code for this function?
13th Jun 2018, 6:06 PM
ODLNT
ODLNT - avatar
+ 1
ODLNT Ohhh Thank you! :) I got the problem. The mistake is Username_Textbox.Text should be Email_Textbox.Text Thank you for helping me ;)
14th Jun 2018, 7:05 AM
Yosua Kristianto
Yosua Kristianto - avatar
0
Hmmmm Wait... I will post the code
13th Jun 2018, 6:33 PM
Yosua Kristianto
Yosua Kristianto - avatar
0
private void RegisterButton_Click(object sender, EventArgs e) { int flag = 0, innerFlag = 0; if (Username_Textbox.Text != "Must use @ and .com") { flag++; } for (int i = 0; i < Username_Textbox.Text.Length; i++) { if (Username_Textbox.Text[i] == '@') { innerFlag++; } } if (Username_Textbox.Text[Username_Textbox.Text.Length - 1] == 'm') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 2] == 'o') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 3] == 'c') { innerFlag++; } if (Username_Textbox.Text[Username_Textbox.Text.Length - 4] == '.') { innerFlag++; } if (innerFlag == 5) { flag++; } if (Username_Textbox.Text != "") { flag++; } if (Password_Textbox.Text != "") { flag++; } if (Confirm_Password.Text == Password_Textbox.Text && Confirm_Password.Text != "") { flag++; } if (Image_Name.Text != "Must jpg or png") { flag++; } flag.ToString(); innerFlag.ToString(); if (flag != 6) { error_label.Text = "Please check the condition!!!"+" Flag is = "+flag+" and innerFlag is = "+innerFlag; } else if (flag == 6) { error_label.Text = "Registration Success!"; } }
13th Jun 2018, 6:33 PM
Yosua Kristianto
Yosua Kristianto - avatar