Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

The Interest Calculation Application

The previous lesson describes how to compute compound interest using a For loop. You studied the code in the previous lesson, and this lesson will build a simple application around that interest calculation.

Figure 9.1 shows the application that you'll create today.

09fig01.gif

Figure 9.1 The interest calculating application's window.

Perform these steps to create the interest calculating application:

  1. Start a new Standard EXE project by selecting File | New Project or double-clicking the Standard EXE icon (the icon you'll most often choose for regular applications).
  2. Change the form's Name property to frmInterest. Change the Caption property to Interest Calculation.
  3. Change the form's StartUpPosition property to 2-CenterScreen. You haven't seen the StartUpPosition property yet; it determines the location of the Form window when the user runs the program. Let Visual Basic center the form on your user's screen because you don't know the exact measurements of the screen that your users will use. If you set StartUpPosition to 2-CenterScreen, Visual Basic always places the form in the middle of the screen no matter what the user's screen size and resolution are. (Use the WindowState property to open the Form window in its maximized state if you want a full-screen Form window when the application starts.)
  4. Now you need to add the labels and text boxes. The form's title label is easy to generate. Place a label on the form and set the following properties:
       Name:                    lblTitle
       
       Alignment:               2-Center
       
       BorderStyle:             1-Fixed Single
       
       Caption:                 Interest Calculator
       
       Font:                    Bold 18
       
       Height:                  495
       
       Left:                    2090
       
       Top:                     240
       
       Width:                   3855
    
    You now must set up a series of three label/text box pairs. Notice that the labels in Figure 9.1 all have hotkeys. Although a label cannot accept the focus, pressing Alt+hotkey sends the focus to the next control in line, which will be the text box next to the label (assuming that you place the text box right after you place the corresponding label).
  5. Set the interest rate label as follows:
       Name:                      lblRate
       
       Alignment:                 1-RightJustify
       
       Caption:                   &Interest rate (8 for 8%):
       
       Font:                      Regular 14
       
       Height:                    375
       
       Left:                      2040
       
       Top:                       1080
       
       Width                      2895
    
  6. Set the interest rate text box as follows:
       Name:                    txtRate
       
       Alignment:               0-LeftJustify
       
       Font:                    10
       
       Height:                  375
       
       Left:                    5160
       
       ToolTipText:             Annual rate investment grows
       
       Top:                     1080
       
       Width:                   615
    
  7. Blank out the Text property so nothing appears in the text box at startup (this can be done by deleting the default value of the Text property). Notice that you're adding ToolTipText at the same time you add the control that the user interacts with.

Share ThisShare This

Informit Network