Here are some rough notes about using VB.
Back to course page.
Start VB.
Find Visual Basic on the Windows Start menu and start it.
The large VB window appears with a New Project dialog box (if there is no dialog box, bring it up by File > New Project).
Select Standard Exe. The VB window shows Project1 with an empty Form1.
Name the project.
Select Project > Project1 Properties. In the Project Properties dialog box, change Project1 to your project name, say Counter.
The title bar on the VB window changes to match.
Name the form and set the form caption.
The Properties window at the right of the VB window shows the properties for the form. The first property at the top of the list is Name. Change the name to, say, frmCounter.
The title bar in the Form window changes to match.
Still in the Properties window, scroll down to Caption. Change the caption to the same name as the project, say Counter.
The title bar on the form itself changes to match.
Save the form (you should always name and save the form before you save the project).
Select File > Save frmCounter As .... The Save Form As dialog box appears. The Save in: textbox shows the name of the folder where the form will be saved. You should create a new folder for this project. Navigate to the folder where you want to keep all your VB projects and click on the new folder icon (a picture of a folder with a little highlight). After you create the new folder, select that folder. Its name should appear in the Save in: box. The form file name frmCounter.frm should appear in the File name: box (if not, type in the correct name). Click on Save.
The form is saved.
Save the project (be sure to name and save the form before you save the project).
Select File > Save Project As .... The Save Project As dialog box appears. The Save in: textbox should show the correct folder (the one you just created for the form). The File name: box should show the correct name (Counter.vbp in this example). Click on Save.
The project is saved.
After you name and save the form and the project, it is a good idea to exit and then restart VB to make sure you can restore your project --- before you invest a lot of work in it.
Start VB.
Find Visual Basic on the Windows Start menu and start it.
The large VB window appears with a New Project dialog box. This time choose the Existing tab (if there is no dialog box, bring it up by File > Open Project).
Navigate to the folder you created earlier. It should contain a .vbp file for the project you created earlier (Counter.vbp in this example). Select that file.
Alternatively, instead of using the Start menu, you can navigate to the project folder using My Computer or Windows Explorer. Then double-clicking on the .vbp file or the .frm file starts VB and opens that project.
The restored project appears in the VB window. The project name appears in the title bar.
Open the form.
An icon for a folder of forms appears in the Project window on the right side of the VB window. Open this folder and select the form you saved. Click on the View Code and View Object icons to display the code or form layout windows.
Now you are ready to add controls and code to the form. At any time, you can use File > Save frmCounter and File > Save Project to save your changes to the form and the project without going through the Save As ... dialogs.
Restore a saved VB program, as described in How to Restore ... above.
It is a good idea to change the project name and the form name, as described in How to Create ... above.
Make changes in the program.
Save the form and the project in a new folder, using Save As ... (not Save) as described in How to Create ... above.
Make sure you save the changed program in a different folder. This is necessary to ensure that the earlier program is preserved. Be sure to save the form first.
Repeat for each control:
Choose the control.
In the Toolbox window at the left, point at a control icon. The name of the control (for example, Label) will appear.
Double click on the control icon.
The control appears in the middle of the form layout window.
Position and size the control.
In the Form Layout window, point at the center of the control. Drag control to the position you want (hold down the left mouse button while you move the mouse).
To size the control, point at one of the little grab boxes at the sides and corners of the control. Drag the side (or corner) to make the size you want.
It is best to set the properties for each control right after you select it and position it.
Use the Properties window at the right.
Select the control from the drop-down menu at the top of the Properties window. Or, click on the control in the form layout window.
A table showing all the control properties appears, with property names in the left column and property values in the right.
The first property is Name. Type in a meaningful name, using the naming
conventions: frm...
for forms, cmd...
for
command buttons, lbl...
for labels, tmr...
for timers etc.
Set the other properties. For command buttons, set alignment, caption and font. For labels, set alignment, caption, font, and (often) background color. For timers, set interval. And so on.
Use the Code window. Find the relevant event subroutine.
For controller Ctlr
and event Event, the subroutine is named
Ctlr_Event, for example cmdEnter_Click
.
Double-clicking on the controller in the Form layout window puts the cursor at the pertinent subroutine in the Code window.
The program window appears, looking much like the form you designed. The controls on the window are active. While the program is running, it behaves like any other window on the desktop: you can move it, minimize it, etc.
The indicator on the VB window title bar changes from design mode to run mode. Many items in the VB window disappear during run mode and many menu and toolbar operations not enabled.
The indicator on the VB window title bar changes from run mode to design mode. Items in the VB window reappear, and menu and toolbar operations are enabled again.
In design mode, you can add or remove controls, change control properties and revise code. Your changes will be in effect when you run the program again.
It is not necessary to use the Save operations before your next program run. It is only necessary to save before you exit VB.
When the program is running, there are several ways to put VB in break mode:
(Could say more about debugging ...)
There are several ways to exit VB.
VB will warn you if you have unsaved work.
Back to top