Each time you begin a new project, the default name, Project1, appears at top of the form. Unless you change the name, every project you work on will be named Project1. To change the name, choose Project, Project1 Properties (see Figure 2.2), and type a new project name. For example, you might enter Project2_1 for this initial project.
The Project Properties dialog box is used to change the name of the project from the default, Project1, to a name of your choosing.
Exercise 2.1 Using the Save Project As Command
This exercise asks you to do very little, but it does introduce you to the file naming conventions. Start Visual Basic, and perform the following steps:
- Open a Standard EXE new project.
- Choose Project, Project1 Properties and change the name of the project to Project2_1. Click OK. This new name should appear on the topmost title bar of Visual Basic.
- Choose File, Save Project As. A dialog box appears and asks if you want to save the file as Form1.frm. If you click Cancel, the form is not saved and you have to rebuild it if you need it. Imagine that you spent an hour perfecting a form. Unless you save it, your work will be lost.
- Before you click Save, navigate to the location where you want to save the file, and assign a name to the form. Assign a unique name – something other than the default, Form1.frm. You can use the notation F2-1.frm to indicate that this form goes with exercise 2.1 (not very clever, but it works). A more descriptive name would be better.
If you want to store the form on a diskette placed in the a: drive of the computer, navigate to the drive and type F2-1.frm.
- After the form has been saved, a second dialog box appears asking you to assign a name to the project. Again, assign a unique name (not the default, Project1.VBP). You can call it P2-1.VBP to indicate that this project goes with Exercise 2.1. Here too, a descriptive project name would be better.
If you want to save the project on a diskette placed in the a: drive of the computer, navigate to the drive and type P2-1.VBP
The Add File and Remove File Commands
Files can be added to, or removed from, the .VBP project file using the file commands contained on the Project menu. When adding or removing files, keep in mind that you are adding or removing files from a project. The following are two Project menu commands that you will use often in this book:
- Add File – Choose Project, Add File to open a dialog box (see Figure 2.4) that enables you to navigate the Windows file directory to identify a previously saved file and to add the file to a project, for example, an .FRM (form), .BAS (coded module), .CLS (class modules), or .RES (resource file). This command is especially important when you use a file built for a different project. Simply identify the file name, and click OK.
- Remove <Name of File> – Choose Project, Remove <Name of File> to remove the file from the current Project that is active (has the focus, a term that is described next).
Other Project menu file commands include Add Form, Add MDI Form, Add Module, and Add Class Module. These enable you to add new types of forms and modules to a project.
The Save File and Save File As Commands
The following are two File menu commands that are used to save a particular file rather than an entire project:
- Save File – Choose File, Save File to save the form or module that is active (has the focus). If the file has previously been saved, this command updates the file. If the file is new, this command prompts you for the name of the file and, once entered, adds the file to a project when the project file (.VBP file) is next saved.
- Save File As – Choose File, Save File As to save the current file to a disk. This option always prompts you for the file name. Like the File, Save Project As command, File, Save File As is used to save a file for the first time or to save a copy of an existing file.
You will find file commands most useful when you want to use the same forms and modules in different projects. There is nothing to prohibit you from using the same form in dozens of projects because each form is saved as a separate file.