Introduction: Create Main Menu in Visual Basic
Have you ever wanted to create your own custom interface kind of like a Main Menu for something? Well this can be achieved using a handy piece of software called Visual Basic, in this program you can create programs that allows you to click on buttons, check boxes and have the program display text. Visual Basic can be downloaded off the internet but be warned some versions of it are not free. This program is perfect if you are making a film and require any type of graphic interface to use as footage in your film.
Step 1: Create New Form
The first thing you need to do is create a new Form, the Form is the grey box that contains all the objects and code of your program. In the bottom right of the screen there is a list of properties for a selected object, in Visual basic its important to give objects a name that starts with the proper abbreviation; for Forms its "frm" then put the Form's actual name in this case "frmGame" inside name box.
Step 2: Add Objects
Now to create the interface you need to add objects to the Form. The toolbar on the left contains icons for all the objects you can add; for this particular program we will use three objects: Labels, Commands, Frames and Option buttons.
The icons for objects are as follows:
Labels = Capital A
Commands = Raised Square to bottom right of Capital A
Frames = Box with "XY" inside just below Capital A
Options = Circle with dot below Command button
To add the object to the form select the object you want then bring your cursor on to the form then click, hold and drag the cursor to achieve desired size. Place a Label at the top, a Frame below with all of your Option buttons inside of it, place another Label below that and two Commands at the bottom. Make sure to name your objects so that when you are coding the code will know what objects you are manipulating and be sure to use proper abbreviations to tell them apart (Labels: lbl, Commands: cmd, Frames: fra, Options: opt) To change the text of the objects go to the Caption box in the Properties bar to the right.
Step 3: Coding
To input code for an object simply double click the object and the code window will open and you will see something like this:
Private Sub *Object Name*_Click()
*Code goes here*
End Sub * Make sure not to alter these two lines of code!
But first we need to create a variable; a variable is a piece of code whose value can be changed during run time. For this program we are creating a Menu that displays text so we are going to be using STRING VARIABLES. In the code window at the top left there is a scroll list that should have the names of all your objects; scroll until you find one that says (General) and select it and type:
Dim strMessage As String *Make sure to declare under (General)!
Now double click each of your OPTION BUTTONS and input this code between the two lines:
strMessage = " *NAME HERE* " * Changes variable to whats in the quotes
Double click on one of your COMMANDS that will become an exit button:
Unload *FORM NAME HERE* *Don't forget the form name!
Now double click your other COMMAND that will become a display or select button and input this code:
lblMessage.Caption = strMessage *Don't forget the label name!
Step 4: Enjoy!
Now to run the program go to the tool bar at the top and press the START button which looks like a small blue arrow. If you followed all the steps properly it should look like the picture after running the program and selecting an option. The program and the creation window are two separate windows so you can minimize everything else and just have the program running on screen. This simple program can be used to create a Custom Interface or Main Menu for almost anything; it's really useful if you need to incorporate something like it in a movie or presentation or anything that needs a cosmetic menu.
We have a be nice policy.
Please be positive and constructive.