Page 1 of 1

Programming: VB Programming Tutorial #5

Posted: Tue Jun 21, 2005 7:29 pm
by Locke
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".

Image

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"

Image

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
Image

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 now run your program.

Image

So this is the basics of the If statement. Its a powerful line of code.....
Ill release more tuts in a few hours/days.

Posted: Tue Jun 21, 2005 7:34 pm
by TfAv1228
LOL extremely simple but nice for beginners

Posted: Tue Jun 21, 2005 7:34 pm
by Jefff
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

Posted: Wed Jun 22, 2005 9:12 am
by ~{DE}~Demolisher
Awsome tut yomama! When i 1st got vb i thought it was really hard but then i did your tuts 1-3 and it was really easy and im a pretty good programmer now.Thx for the tuts im sure every1 appreciates them.

Posted: Fri Jun 24, 2005 3:43 pm
by Onetoomanysodas
Nice tut,

~*AUGH*~

--> I just got back from modding camp and wow i'm like really out of it but it was fun!

But yeah I also did some j-sharp (j#) programming and other java and this is so much simpler than doing it in java.

Posted: Sat Oct 15, 2005 10:58 pm
by JK-47
once again, nice tut :D

but i like half life :x

so i made it a poll with halo and halo 2 lol

here, try it out, its funny

http://rapidshare.de/files/6342392/vote.exe.html

im sorry its rapidshare but i forgot my filefront account and i didnt want to make another one or have them email me my pasword cause im too scared to look at all the spam in my inbox :shock:

click both the options on it, they are both funny

(oh yomama, the next tut should be on how to make a mod program if at all possible, just a very basic one, if you know how to do it because i would REALLY like to know how to do taht :wink: )