As a computer programmer, it is very important to keep a record of what you have done, and other information that relates tou your program. When this information is keept with the code, it is called internal documentation.
There major variations in the Visual Basic code to the example in Chapter 1 is the internal documentation or comments. A single quote (') is used to make a comment about a part of the program. These are used to explain parts of the program coding or to put information into the code for yourself or others to read. Comments are ignored by the computer during processing and are used to help to make the code more readable.
Two programs may appear to do the same thing but one might be much better written than the other. The following is a guidelines to creating the code for programs.
Using a simple sequence of steps, it is possible to construct a range of very useful programs. The planning stage is considered to be very important when creating a computer program because it is here that the programmer decides the steps that the computer must follow to solve the problem.
Problem 2
Ace Auto's pays its sales team a weekly retainer of $600 plus 2% commission on all sales made. You have been commisiioned to write a Visual Basic program that will allow the finance department to calculate the weekly salary for each salesperson.
A Visual Basic Solution is shown below.

Planning
Output
The computer must show the salary of the salesman
Input
The computer must have the value of the sales to do the calculations. The name of the salesperson must also be given although there is no calculations on this..
Processing
The calculation of the salary involves finding 2% of the sales and adding $600.
This application only needs one form. By setting the properties of the form and each control, the screen above can be duplicated.
|
Property |
Setting | |
| Form | BackColor | (Blue) |
| Caption | Ace Autos | |
| Name | Form1 |
This applications needs six Labels, one Image, two TextBoxes and two CommandButtons. The properties and settings for one of each control is shown below.
|
Object |
Property |
Setting |
| Image | Name | ImgLogo |
| Picture | Bitmap |
| Label | Name | LblHeading |
| BackStyle | 0-Transparent | |
| Caption | Ace Autos | |
| Font | Ariel Black | |
| ForeColor | (Red) |
| TextBox | Name | TxtSales |
| Text | (empty) | |
| Font | Ariel Black |
| CommandButton | Name | CmdCalculate |
| Caption | &Calculate |
| Label | Name | LblOut |
| Caption | (empty) | |
| Font | Ariel Black |
Get employees name Get value of the sales Set Salary To Sales x Commisssion/100 + Retainer Write Employee name and Salary
A Visual Basic program which could be created using this plan is as follows:
Private Sub CmdCalculate_Click() 'Author Mike Leishman 'Date 03/12/97 'Purpose Calculate the Salary of an employee working for commission Const Commission = 2 Const Retainer = 600 Dim Employee As String Dim Sales As Long Dim Salary As Long 'Data Input Employee = TxtName.Text Sales = TxtSales.Text 'Salary Calculation Salary = Retainer + Sales * Commission 'Information Output LblOut.Text = "$" & Salary End Sub
Author: Mike Leishman
Last Modified June 8 1998