Adding, deleting, and saving files
The use of multiple files in engineering is similar to the use of engineering itself.
To add files to your project, follow these steps:
1. Select "Project", "Add filetype" (here, filetype is the type of file). The Add FileType dialog box (Figure 4.2) is displayed.
2. Select an existing file or a new file type and choose Open. When you add a file to your project, you simply incorporate a reference to the existing file into the project, rather than adding a copy of the file. Therefore, if you change the file and save it, this change affects any project that contains the file. If you want to change the file without affecting other projects, select the file in the Project Explorer, choose FileName Save As from the File menu, and then save the file with a new file name.
Note You can drag files from Windows Explorer, File Manager, or My Network Places and put them into the engineering window to add them to a project. You can also drag an. ocx file and put it into the toolbox to add a new control.
To remove a file from your project, follow these steps:
1. In the Project Explorer, select the file.
2. From the "Project" menu, choose "Delete filename."
3. This file will be removed from the project, but still exists on disk. If you delete a file from the project, Visual Basic updates this information in the project file when you save the project. However, if you delete a file outside of Visual Basic, Visual Basic cannot update the project file, so when you open this project, Visual Basic displays an error message warning that a file is missing.
To save only the file without saving the project, follow these steps:
1. Select this file in the Project Explorer.
2. From the "File" menu, choose "Save filename."
Merging text
You can also insert existing text into a code module from other files. This is useful when adding a constant list or adding code snippets that might be saved in a text file.
To insert a text file into your code, follow these steps:
1. From the Project window, select the form or module where you want to insert the code.
2. Select the "View Code" button to move the cursor to where you want to insert the code in the Code Editor.
3. From the Edit menu, choose Insert File.
4. Select the text file name you want to insert, and choose Open.
Note If you use text or a code editor other than visual Basic to edit the VisualBasic code, be careful not to change the Vb_predeclaredid settings. It is particularly noteworthy that changing this property can cause serious problems for globalmultiuse and GlobalSingleUse classes.
In general, do not edit these properties manually, because doing so will cause the module to be in an internally inconsistent state.
Adding controls to the project
The set of controls available in the Toolbox can be defined separately for each project. Any given control must be in the toolbox before it can be added to the project's form. The basic set of standard controls that are often present in the toolbox are described in Chapter three, "Forms, controls, and menus."
Adding ActiveX controls to your project
After you add ActiveX controls and pluggable objects to the toolbox, you can add them to your project.
To add a control to the project's toolbox, perform the following:
1. Choose "Parts" from the "Project" menu. The Parts dialog box is displayed, as shown in Figure 4.3. The items listed in this dialog box contain all registered ActiveX controls, pluggable objects, and an ActiveX designer.
2. To add a control to the toolbox (with an. ocx file name extension) or to insert an object, select the check box to the left of the control name.
To view a control that has an. ocx file name extension, select the Control tab. To view pluggable objects, such as Microsoft Excel charts, select the Pluggable Objects tab.
3. Select OK to close the Parts dialog box. All of the ActiveX controls that you selected will now appear in the toolbox.
To add an ActiveX control to the Parts dialog box, select the Browse button and search for other directories to find files with an. ocx extension. Visual Basic automatically selects this check box when you add an ActiveX control to the list of available controls.
Note that each ActiveX control has a file with a. oca extension. The file stores cached library information and other data specific to that control. Files with a. oca extension are usually stored in the same directory as the ActiveX control and can be rebuilt when needed (file size and date can be changed).
Remove a control from the project
To remove a control from your project, follow these steps:
1. From the "Project" menu, choose "Part".
Displays the Parts dialog box.
2. Clear the check box next to each control that you want to delete.
The icons for these controls are removed from the toolbox.
Note If an instance of a control is used by any form in this project, you cannot remove the control from the Toolbox.
Objects that use other applications
You can also use objects from other applications, such as objects that are contained in a Microsoft Excel object library, whether as a control in the toolbox or as a programmable object in your code. To add an object to the toolbox, see "Adding Controls in Engineering" earlier in this chapter.
To make objects in other applications available in code, but not as controls, you should set a reference to the object library for that application.
To add a reference to the object library for another application, follow these steps:
1. From the "Project" menu, choose "Reference".
The Reference dialog box is displayed, as shown in Figure 4.4.
2. Select the check box next to each reference you want to add to the project.
To add a reference to an application that is not listed in the Reference dialog box, select the Browse button and select the application.
3. Select OK to add the selected reference to the project.
If you are not using any of the objects in the reference library, you should clear the check box for that reference to minimize the number of object references that visual Basic must resolve, which can reduce the amount of time that the project compilation takes.
Once you have set up a reference to the desired object library, choose Object Browser from the View menu to find a specific object and its methods and properties in the Object Browser. You can use any object that is listed in the Object Browser in your code.
For more information about the Object Browser, see "Finding Object Information" in chapter Nineth, "Programming with objects."
Working with resource files
A resource file allows you to bring together the body and bitmaps of all the specific versions used by an application. It can contain constant declarations, icons, screen text, and other data that can be changed between localized versions or between different revisions or between special configurations.
To add a file to the project, follow these steps:
1. From the "Project" menu, select "Add File".
The Add File dialog box is displayed.
2. Select an existing resource file (. res) and choose Open.
A project can have only one resource file; If you add a second file with the. res extension, an error occurs.
For more information about resource file content, see Chapter 16th, "International distribution."
To make and run an executable file
Use the following procedure to make an executable file (. exe) from Visual Basic.
To make an executable file in Visual Basic, follow these steps:
1. Choose "Make Projectname.exe" from the "File" menu, where ProjectName is the application name for the project.
2. In order to rewrite the existing executable file with a new version, type the file name or browse the directory to select an existing file name.
3. Click the "Options" button to specify some details about the specific version of the execution file in the Project Properties dialog box.
4. To modify the project version number, set the appropriate major version number, minor version number, and revision number. When automatic upgrade is selected, the revision number automatically increases every time you run the make projectname. exe command for the project.
5. To specify a new name for the application, under Application, type the new name in the title box. If you want to specify a new icon, select one from the list.
6. You can also enter various versions of the version-specific comments (comments, company name, trademark and copyright information, and so on) under the Version information box by selecting the Theme from the list box and entering information in the text box.
7. Select OK, close the Project Properties dialog box, and then select OK in the Make appname. EXE dialog box to compile and connect the executable file. Double-click the icon for the executable file to run the executable file, as you would any other windows-based application.
Note It is useful to build executable files from the command line in a DOS session if you want to compile a project in a planned way. In batch file key: Vb6/make projectname[.vbp] [exename]
For projectname, type the project file name. The variable exename is used to rename the resulting executable file.
Conditional compilation
Conditional compilation allows you to selectively compile portions of a program. You can incorporate the specifics of your program into different versions, such as filters for dates and currency displays for an application in a different language version.
For more information about conditional compilation, see "Using Conditional Compilation" in chapter eighth, "re-discussing programming."
Set Engineering options
Visual Basic allows you to customize each project by setting some properties. Use the Project Properties dialog box, which you can set by using the project Properties command on the Project menu. The property settings are saved in the project file (. vbp).
The following table lists some of the options that you can set:
There are a number of other options that are also available, including compilation, parts, and multithreading. If you want to access some of the more advanced options, you can get more information in the online Help lookup.
For more information about learning about environment option settings that affect all projects, see chapter II, "Developing applications in visual Basic."