Programming: VB Programming Tutorial #5
Posted: Tue Jun 21, 2005 7:29 pm
I got some more time, and have decided to write another tut. This one is a little more advanced. There going to be more advanced as time progresses.
Today, you will learn about "If" statements. An If statement is basicly saying, if this happens then do this. So in Halo terms, If the Mc gets Killed then mc respawns. Simple enough eh?
So, as always, make a new Standard Exe project. Keep the form name the same and change the caption to "If Statements".
Now that you have completed this, lets put some objects on. Draw out a label, and set the caption to "Wich is better. Halo2 or Half-life 2?'. Then draw out 2 options onto the form. Name them opt1 and opt2. After, make a command button and change the caption to "Submit"
Now for the coding. Double click Command1 to bring up the code. Use
So "If Opt1.value = true then" means If you selected Option1 then do something.
The msgbox is what it does when the first line/condition happens. And the last line "End if" means the If statement is over. The code wont work without it.
Also, the above coding could be writtin in an If-Then-Else format. Here's an example:
So now run your program.
So this is the basics of the If statement. Its a powerful line of code.....
Ill release more tuts in a few hours/days.
Today, you will learn about "If" statements. An If statement is basicly saying, if this happens then do this. So in Halo terms, If the Mc gets Killed then mc respawns. Simple enough eh?
So, as always, make a new Standard Exe project. Keep the form name the same and change the caption to "If Statements".
Now that you have completed this, lets put some objects on. Draw out a label, and set the caption to "Wich is better. Halo2 or Half-life 2?'. Then draw out 2 options onto the form. Name them opt1 and opt2. After, make a command button and change the caption to "Submit"
Now for the coding. Double click Command1 to bring up the code. Use
Code: Select all
If opt1.Value = True Then
MsgBox "Woot", vbExclamation, "Halo2"
End If
If opt2.Value = True Then
MsgBox "Not Woot", vbExclamation, "Half-Life 2"
End If
So "If Opt1.value = true then" means If you selected Option1 then do something.
The msgbox is what it does when the first line/condition happens. And the last line "End if" means the If statement is over. The code wont work without it.
Also, the above coding could be writtin in an If-Then-Else format. Here's an example:
Code: Select all
If opt1.Value = True Then
MsgBox "Woot", vbExclamation, "Halo2"
ElseIf opt2.Value = True Then
MsgBox "Not Woot", vbExclamation, "Half-Life 2"
End If
So this is the basics of the If statement. Its a powerful line of code.....
Ill release more tuts in a few hours/days.