Tutorial level: Beginners: If/Then/Else statements
Welcome back, today we will move on to If/Then/Else statements, which is exactly as it sounds.
Just like when you add an event to a map in DF, the event is set up as If "something happens" Then "something else happens".
This concept applies to programming the same way.
1.) Start out with an application, have a Button, and TextBox. Double click button, and get to Code-View.
2.) Now, what we want our code to do, is IF the TextBox text is "Hello" THEN show a messagebox saying "Correct Text"
3.) Now lets start, type:
Now run the program, type "Hello" (w/ out quotes) into the TextBox, then click the button, you will get the message.
4.) Alright that's simple, lets add an exception, exceptions are "Else" statements. Here is how an Else statement works:
Else statements are used if the IF part of the IF/Then statement is not true.
Alright, so lets say that the user typed something other than Hello in the TextBox, we want a message to show saying "Wrong Text"
5.) Now go to the code you type earlier, go below the MessageBox.Show("Correct Text") part, then type this:
Should look like this:
Run the program again, type something diff. in the Textbox, and press the button.
You should now understand the concept of If/Then/Else statements.
Check in for more,