DFBarracks - Forums




Delta Force Barracks Forums - Powered by XMB 1.9.11
Delta Force Barracks Forums
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: Tutorial level: Beginners: If/Then/Else statements
bullet magnet
Captain
****


Avatar


Posts: 263
Registered: 6-26-2005
Member Is Offline

Mood: Modding

[*] posted on 6-27-2007 at 04:30 PM
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:

Code:
[size=3]If Textbox1.Text = "Hello" Then MessageBox.Show("Correct Text") End If[/size]


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:

Code:
[size=3]Else MessageBox.Show("Wrong Text")[/size]


Should look like this:
Code:
[size=3]If TextBox1.Text = "Hello" Then MessageBox.Show("Correct Text") Else MessageBox.Show("Wrong Text") End If[/size]


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,

Bullet Magnet





View user's profile View All Posts By User

  Go To Top

Powered by XMB 1.9.11
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 15] [PHP: 55.5% - SQL: 44.5%]












Copyright © 2002 - 2008 All Rights Reserved - DFBarracks.com
Site Design by A.Bullet - ScreamingDemon.com