|
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
The procedure for changing the properties of the other Text Box controls is the same: Click on the Text Box to select it, then change the properties in the Properties window. All of the Text Box controls should be given a blank Text property. Table 2.1 shows the proper values for the Name properties. We still have one more property to change. While the first three Text Boxes are designed to accept input from the user, the last onetxtMonthlyPaymentdoes not need to accept user input. To prevent errors, therefore, we will lock it, which means the user cannot change it while the program is running. (The program will still be able to display the answer there, of course.) Click on the Text Box next to the Monthly payment label, then click on the Locked property in the properties window. The property setting in the right column will display False with a small button displaying a downward-pointing arrow. Click on the button to display a list of possible settings for the property; in this case, there are only two: True and False. Click on True to lock the Text Box. I want to point out two things about the names we assigned to the Text Box controls. Each name consists of two parts: a prefix to identify the type of control and an identifier that describes the function of the control. This is not necessary as far as Visual Basic is concernedwe could have called them Moe, Larry, and Curlybut when you are writing a larger program with lots of controls and code, you will find it useful to be able to tell from the name of a control what type of control it is and what its function is. Once all of the Text Box controls are complete, one more step will complete the visual interface.
Adding A Command Button During the planning stage, we decided that the Mortgage Calculator should have a Quit button allowing the user to exit the program. Visual Basics Command Button control is what we need, and we place this on the form in the same manner as the other controls. Click on its icon in the toolbox (the icon is a small gray rectangle, normally located just below the Text Box icon), then drag on the form to place the control. Youll need to change the Command Buttons Name and Caption properties, too. You already learned how to do this by using the Properties window; set the Name property to cmdExit and the caption property to Exit. Adjusting The Form Size If you find that the forms size is too big or too small for the controls you have placed on it, the problem is easily fixed. All you need do is select the form by clicking on it, then point at one of its dark handles and simply drag the form to the desired size. This might be a good time to fine-tune the position and sizes of the controls as well. Change each control that you want to adjust by dragging it to its new position, or dragging its handles to change its size. Changing The Forms Caption While its not strictly necessary for the program to function, we can do one more thing to improve its appearance: We can have the main program windowthe formdisplay the name of the program while its running. As you might guess by now, the text displayed in the windows title bar is controlled by a property. In this case, it happens to be a property of the form, and heres how to change it:
The visual design stage of this project is now complete, and your Visual Basic design screen should look more or less like Figure 2.6. We can now move to the third stage of development: writing the code. But first, saving the project to disk will safeguard our work against your three-year-old tripping over the computers power cord or some other unexpected disaster.
Saving The Project As you work on a Visual Basic project, all associated information is stored in your computers random access memory (RAM). The problem with RAM is that information is lost when the power is turned off. If you want your project to be there tomorrow, you must save it to disk. If you have any experience with other Windows programs, you probably already know how to do this, but Ill run through the procedure just in case. This step has two parts: saving the form and saving the project. Pull down the File menu by clicking on File in the Menu window or by pressing Alt+F. Next, select the Save Project command from the menu by clicking on it or by pressing v. Visual Basic will display the Save File As dialog box, in which you specify a name for the disk file that the form is stored in. In the dialog boxs File Name box, Visual Basic suggests a default file name that is the same as the forms Name property. Because we have not changed the forms Name property from its default value of Form1, thats what Visual Basic will suggest as a file name. We can do much better, however. Type Mortgage and press Enter. Next, Visual Basic displays the Save Project As dialog box. Again, we have a File Name box with a default project name, typically Project1. Type Mortgage Calculator and press Enter. If, during this process, you are asked whether you should add the project to SourceSafe, just click on No. Thats all there is to it. Your project is now saved to disk, and youll be able to load and continue working on it the next time you use your computer. Now that you have assigned file names to your project and form, pressing Ctrl+S automatically saves them under the existing names. Do this once in a while as you work on a projectand, of course, when you are finished and ready to quit Visual Basic. Step 3: Writing The CodeThe Mortgage Calculators visual interface is complete. You can run the program now by pressing F5, by clicking on the Start button (the right-pointing arrowhead) on the toolbar, or by selecting Start from the Run menu. Youll see the window you designed with all of its elements in place. Youll even be able to enter text in the three top Text Box controls. The program does not do anything, however, and youll have to click on the Close button in the title bar (the button with the X on it) to end the program and return to Visual Basic.
|
![]() |