First off, start Visual Basic. For this tutorial, I am using Visual Basic 6.0. Visual Basic will automatically open up a new project. You will see a form inside of another form. The inside form is what your user interface will look like. This is the part that you will see when you run your program. If you would like you can go up to Run and press start. This action will run your program(you can also run your program by pressing F5). Right now it does absolutely nothing but pop up a form. You can close the form by pushing the close button at the top right hand corner of your form(it's the little x). This will end your program.
Now that you know how to run your program, let's build a program that does something! You may have noticed that there is a toolbar on the left of your Visual Basic interface. This toolbar includes many of the most important objects you will be using in the future. Find the toolbutton for making a Label. A Label displays text on your form. Click on it. If you drag across your form with your mouse, you will make a label, named Label. It also displays the text "Label1". If you turn your eyes to the right of the screen (unless you have moved the interface around), you will find a Properties window. Scroll down if you need to until you find the caption property. In the box next to caption it will says Label1. This property changes the text displayed by the label. Change the caption to "This is my first program". Run your program. Notice what the label says. You can change the caption to whatever you would like.
The label's name will still be Label1, even though its caption(or text) isn't. Find the name property in the properties window. Click in the box next to name and change its name to something that will tell you what it is. You can leave it Label1, but I do not recommend you do this because when you have 10 labels on the same page, the name Label1 or Label6 tells you absolutely nothing about what that label says. Change it to something like lblFirstProg(standing for First Program). This is a good habit to develop.
Well you are probably thinking, "Come on, I thought you said a program that actaully does something! That did absolutely nothing!" Well, here goes(I hope your ready for this) let's make a button that exits the program. Go to our handy little tool bar and click on the button for making buttons, this button builds a button but I'm bettin' that (ok I'll stop.) Go to the form and drag the mouse to make a button. At the moment the button will read Command1. You can change that with the caption property. You alreadly know how to do that so I won't go into the details. Make the caption say Exit. You also need to change the button name to cmdExitProg. Why? The name ExitProg tells you what the button does, and cmd tells you that it is a command. It EXITs the PROGram.
Now on the form, double click on your button. You will now see actual program code. It will read:
Private Sub cmdExitProg_Click()
End Sub
First say "ooooooooooooooooooooo." Now say "aaahhhhhhhhhhhh." (It will make everybody come look at your monitor.)
This is the Sub routine for the button. Anything that you put inside of the Sub will be carried out when your button is pushed (or clicked). Inside of this sub we will put End. Like this:
Private Sub cmdExitProg_Click()
End
End Sub
Run your program. Try clicking on your button. Did it work? If not check your code. You might have done something wrong. Click here to download this program. If you can't seem to get this to work, you can email us for help.
Copyright ©2000 by Kyle Baker. Please read our disclaimer.