Programming: Select Case Tutorial In VB6
Posted: Sat Oct 01, 2005 6:17 am
Hi, welcome to my tutorial
I learnt this stuff 2 days ago so I thought I'd make a tutorial out of it.
Basically, Select and case are like "If" and "End If's" however you dont need as many, it can cut the coding down alot which is fab.
So now heres an example of coding. Sorry for it not being Halo related, I'm not too sure how you would make it Halo related, anyways.
Open up Visual Basic 6, and create a new Standart Exe.
In this you won't need any objects on the form, its ALL coding. You can use other ways to do a few things, like hidding the form but I like to show it in coding, so it helps you.
Double click the Form, so it comes upto the Form_Load section. This is where the coding will be!
Firstly you need to Dim the type of data you will be using, this also makes the coding shorter keeping the file size down too.
This basically tells the program that when you use "Age" in your coding, you'r going to be using the output of the inputbox.
**Additional piece of code**
Just means that when you run the program, it will hide the form
****
Next we will be creating an input box so you can input the data. When we Declared that Age was a single it also made the computer rememer what you input.
How we have made the input box, its asking for your age, also we have started the Select case so it knows what we are going to be using Select case for (age)
This basically means, If the number you input is 18 or above.
***For this please press the Tab key in visual basic, this will now indent the coding properly, so the coding is within the "Case" command, basically it means "Case" is like brackets, and the indent is just another line.
This will display a message box saying your old enough, only if your age is 18 or over (as its in the case)
Now we are making it so if the number is "17" then all this will happen (whats in the case)
<< please note that is indeted as well, using tab key in VB6.
Just displays a messege box
Means, if its any number thats Else from the last cases, the action it will take is in this case, for this example, it means if the number put in is NOT 18 or over, or 17, then it will run this code (means 0 - 16)
Tells the program to end the select case, IE closing the "Select Case" brackets.
Just tells the program, once all the coding above has happened, it will close the program.
Here is the coding from my program

Basically, Select and case are like "If" and "End If's" however you dont need as many, it can cut the coding down alot which is fab.
So now heres an example of coding. Sorry for it not being Halo related, I'm not too sure how you would make it Halo related, anyways.
Open up Visual Basic 6, and create a new Standart Exe.
In this you won't need any objects on the form, its ALL coding. You can use other ways to do a few things, like hidding the form but I like to show it in coding, so it helps you.
Double click the Form, so it comes upto the Form_Load section. This is where the coding will be!

Firstly you need to Dim the type of data you will be using, this also makes the coding shorter keeping the file size down too.
Code: Select all
Dim Age As Single
**Additional piece of code**
Code: Select all
Form1.Visible = False
****
Next we will be creating an input box so you can input the data. When we Declared that Age was a single it also made the computer rememer what you input.
Code: Select all
Age = InputBox("How old are you?", "Age Test")
Select Case Age
Code: Select all
Case Is >=18
***For this please press the Tab key in visual basic, this will now indent the coding properly, so the coding is within the "Case" command, basically it means "Case" is like brackets, and the indent is just another line.
Code: Select all
MsgBox "You are old enough to drive!"
Code: Select all
Case 17
Code: Select all
MsgBox "You can drive next year!"
Just displays a messege box
Code: Select all
Case Else
Code: Select all
MsgBox "You are too young to drive"
Code: Select all
End Select
Code: Select all
Unload Me
Here is the coding from my program
Code: Select all
Private Sub Form_Load()
Dim Age As Single
Form1.Visible = False
Age = InputBox("How old are you?", "Age Test")
Select Case Age
Case Is >= 18
MsgBox "You are old enough to drive!"
Case 17
MsgBox "You can drive next year!"
Case Else
MsgBox "You are too young to drive"
End Select
End
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim Msg, Style, Title, Response, MyString
Msg = "Are you sure you want to terminate this program