Working with the VB IDE – Part 5
(Running, Saving, Closing, and Re-opening a Project)
Continuing with the "Hello World" program, continue with the following steps.
· Click the Start button (shown below, looks like a VCR "play" button) on the VB toolbar to run the program. (Other ways to run a program would be to use Run à Start from the VB menu bar or to press the F5 key.)
If you followed the recommendation made at the beginning of this chapter to set "Prompt to save changes" under "When a program starts" on the Environment tab of the Tools à Options dialog box, then the following dialog box will appear, asking you if want to save the changes you have made. At this point, two files need to be saved: (1) the project file (a text file that VB maintains, which contains a list of all the forms and modules that make up the project as well as the property settings for the project and related information), and (2) the form file (a text file that contains information that VB uses to build the form and any controls you have placed on it, as well as all of the code that you have written for the form).
· Click Yes to save the files.
· The first dialog box that appears (shown below) asks you to save the form file. Form files have an extension of .frm, and the filename of the form defaults to the internal name you gave the form earlier (in this case frmFirst). We'll accept the default name, but we should save our project in a new directory (the default location for files to be saved with most installations of VB6 is C:\Program Files\Microsoft Visual Studio\VB98) – so before clicking Save, go to the "Save in" drop-down box, and navigate to Desktop.
· Once you've changed the "Save in" drop-down to point to Desktop, click the New Folder icon, and in the new folder that appears, rename it from "New Folder" to "First VB Project".
· Double-click the First VB Project folder you've just created so that the "Save in" drop-down box points to it, then click the Save button:
· The second dialog box that appears asks you to save the project file. Project files have an extension of .vbp, and the filename of the project defaults to the internal name you gave the project earlier (in this case prjFirst). We'll accept the default name, and the location defaults to the folder we just created, so just click Save:
· At this point, if Source Safe is installed on your machine, you will be asked if you want to add the project to Source Safe. Exercises and tutorials such as this should not be added to Source Safe; therefore, respond No to this prompt:
· At this point, your program will run. The first thing you will see is the run-time version of your form, waiting for the user to do something:
At this point, exit VB by either going to the VB menu and selecting File à Exit, or by just clicking the Windows "X" button.
There are two basic ways to open an existing VB project. One way is through Windows, the other is through VB itself.
If you open the folder in which you saved your VB project, you may see something like the following:
You'll recognize the two files that you saved (frmFirst.frm and prjFirst.vbp), but you'll also see that VB creates additional files associated with your project (these are files that VB creates automatically; you will not explicitly save these files). Following is a brief explanation of additional files that might be saved by VB:
A .vbw file (VB workspace file) contains information about where you left the position of each window in your project the last time you worked on it in the IDE (this is not an essential file – if it's missing, VB will use defaults to position the windows when you load your project).
An .scc file (source code control file) will be present if SourceSafe is installed on your machine. The .scc file indicates whether or not the project is under source code control (if this file is missing and SourceSafe is installed, you will get the "Add this project to SourceSafe?" prompt when you load the project).
Although not needed in this project, an important file type is the .frx file, which will contain any binary information associated with your form. If you would have added any icons or other graphical elements to the form, VB would have automatically created and saved an associated .frx file when you saved the .frm file. If an .frx file is created, it is an essential file – if it is missing, your form will lack the graphic elements you have added and you will have to do extra work to get the form back to its present state (for example, if you have a toolbar that is associated with 25 icons in an image list, it can be quite tedious to restore that).
Other files that can be associated with a VB project are "standard" modules (with a .bas extension) and class modules (with a .cls extension). These are files that you would save explicitly, like form files (.frm files). Both .bas and .cls files will be explored later.
In any event, to open an existing VB project from Windows, it is important to remember that you double-click the .vbp icon. This will open the project file in VB and bring in all the necessary forms and cause VB to apply the information found in the associated files. In Windows, do NOT double-click on a .frm, .bas, or .cls file. This will cause that particular file to opened in VB, but it will not have a project association and VB will make it part of a new default project. If you do this in error, just quit VB without saving anything.
To open an existing project through VB, start VB, and when the "New Project" dialog box comes up, go to the "Recent" tab, select your project, and click the Open button.
Download the VB project code for the example presented in this section here.