ICT - Programming
ICT - Programming
INFORMATION
AND
COMMUNICATION TECHNOLOGY
LEARNING MODULE
PROGRAMMING
1. What is it?
2. Who is it for?
This module is for students who are taking the ICT subject as their elective
and for those who are interested in ICT.
No. The content of this module will enable you to acquire the knowledge.
1
DRAFT
TOPIC : Problem Analysis
LEARNING OUTCOMES :
DURATION : 2 periods
REFERENCES :
2
DRAFT
READING ACTIVITY
We solve all kinds of problems in our daily life. A problem may involve how to
commute to school, work or which homework to do first. Programming is the
same. You need to make a clear statement of the problem you are trying to solve.
Based on the information given, read the situation below and define the
problem, input, process and output.
Situation
Encik Malik is the manager of Enviro Car Enterprise. He asks you to develop a
system to calculate the monthly instalment for every potential customer.
Encik Malik has made an appointment to see you at his office at 9.00 am on
Thursday morning
En. Malik : Good morning. Ahh.. You are punctual. I like that.
En. Malik : Have a sit. Let us discuss the problems that I’m facing.
En. Malik : When my customer decides to buy a car, I will get the customer’s
details and fill it in a form. My problem is, I have to calculate the
monthly instalment manually. It is very tiring as I always have to
recalculate to make sure there are no mistake.
En. Malik : Now the prices of cars has gone down and I foresee that the
number of my customers is increasing. This phenomenon has
increased my workload.
3
DRAFT
You : I see. You mentioned that you have to calculate the monthly
instalments. Is there any other information that you need to give to
your customer?
En. Malik : Usually I will give them the instalment details including the monthly
balance every month until they complete their payments.
En. Malik : I need to know the car model, car price, down payment, number
of years for the loan, and its related annual interest percentage.
You : Yes, thank you. Another question, does your customer decide on
the payment period?
En. Malik : Yes. If the customer is a government servant, we will let them pay
either 10, 7 or 5 years. Otherwise the payment period will be 7 or 5
years only.
You : OK. Is there any other information that you need to tell me about
your manual system?
You : Alright, I’ll discuss with my team members and will inform you then.
Thank you.
4
DRAFT
WRITING ACTIVITY
2. Identify the input En. Malik needs to collect everytime he meets a potential
customer.
3. Identify the necessary output En. Malik sees in his manual system.
5
DRAFT
6
DRAFT
TOPIC : Program Design
LEARNING OUTCOMES:
1. Write pseudocode
2. Create flowchart
3. Design user interface
DURATION : 4 periods
READING ACTIVITY
7
DRAFT
Pseudocode
PROGRAM Calculate_Instalment
END PROGRAM
8
DRAFT
Flowchart
9
DRAFT
This sample flow chart is to assist you to develop a program. See Figure 1.
Start
Read
Customer Name,
Net Income
Yes
Read
Car Model,
Car Price,
Down Payment,
Annual Interest Percentage,
Number of Years
Calculate
Monthly Instalment
Print
Monthly Instalment
Stop
10
DRAFT
WRITING ACTIVITY
Design user interface is a simple layout of the screen you want to design for your
customer. See the two examples below for input and output.
Name
11
DRAFT
Draw your design user interface, based on the input and output you have
answered in Problem Analysis Stage (Page 5).
12
DRAFT
TOPIC : Coding
LEARNING OUTCOMES :
DURATION : 14 periods
13
DRAFT
HANDS-ON ACTIVITY
What is coding
Coding is the next step after the program logic has been formulated using the
appropriate programming language. It also refers to entering the list of
commands that becomes a computer program.
Starting a project
In this activity you’ll start building Enviro program by creating a new project and
then using controls in the toolbox to construct the user interface.
1. After clicking on the Visual Basic program, double click on Standard EXE
button as shown in Figure 2.
14
DRAFT
2. After that you will see the screen shown in Figure 3.
3. To start a new programming project, on the File menu, click the New Project
command.
4. Click OK to create a standard 32-bit Visual Basic application.
15
DRAFT
5. The picture shown in Figure 4 is about the most useful toolbox control you will
use in your Visual Basic program:
TextBox PictureBox
CheckBox Label
Option CommandButton
ListBox ComboBox
Frame
Image
16
DRAFT
3. To change the settings for the command button, click the first command
button (Command1) on the form.
4. Double-click it to open the Properties window title bar.
5. The Properties window is enlarged to full size, as shown in the illustration on
Figure 6.
6. The Properties window lists the settings for the first command button. These
include settings for the background color, caption, font height and width of the
command button.
7. Double-click the Caption property in the left column of the Properties window.
8. The current Caption setting ("Command1") is highlighted in the Properties
window.
9. Type Your Instalment and press Enter.
10. The Caption property changes to " Your Instalment " in the Properties window
and on the form.
11. Add another two new command buttons by repeating step 1.
12. Change their properties by repeating step 4 – 10, according to the table
shown in Table 2.
17
DRAFT
13. When you have finished adding all the command buttons, you will see the
result as shown in Figure 7.
You can delete an object by selecting the object on the form and then pressing
Del key.
Adding labels
1. Click the Label control in the toolbox, and then drag it onto the form, like the
shown in Figure 8.
18
DRAFT
2. Change the properties for the labels in the program. Click the first number
label,
3. Click the Name property, and type lblTitle into the property.
4. Double-click the Caption property, and modify it into Enviro Car Enterprise.
5. Click the BackColor property and change it into &H00FFFF00&. See the
result on Figure 9
6. You have finished with the first label. Now you will have to change the Name,
Caption and BackColor properties of the last nine labels. Create nine more
labels, named Label2, Label3, Label4, Label5, Label6, Label7, Label8, Label9
and Label10 on the form by repeating step 1.
19
DRAFT
7. Change their properties by repeating step 2 – 5, according to the table shown
in Table 3.
To change the BackColor properties for last nine labels, you can change their
properties in one step.
1. Hold down the Shift key, and click the second, third to the ninth labels.
2. You will see a set of selection rectangles appearing around each label that
you click.
3. When you have selected them all, release the Shift key.
4. Double-click the BackColor property, and then type &H00FFFF00&.
20
DRAFT
8. When you have finished, your ten labels should look like those in the following
illustration (Figure 10).
Label1
Label2
Label3
Label4
Label5
Label6
Label7
Label8
Label9
Label10
21
DRAFT
Adding textbox
A textbox is a special user interface element designed to receive input from the
user as well as to display the output. It can handle text and numbers but not
images.
1. Click the TextBox control in the toolbox, and then drag it onto the form, like
the one shown in Figure 11.
Textbox1
22
DRAFT
6. Change their properties by repeating step 3 and step 4, according to the table
shown in Table 4.
7. When you have finished, your five text boxes should look like those in the
following illustration (Figure 12).
Textbox1
Textbox2
Textbox3
Textbox4
Textbox5
23
DRAFT
Adding Combo Box
1. Click the ComboBox control in the toolbox, and then drag it onto the form,
like the one shown in Figure 13.
ComboBox1
24
DRAFT
5. When you have finished, your combo box should look like the following
illustration (Figure 14).
25
DRAFT
Adding Option
An Option is a special user interface element designed to let the user select it as
one of the choices.
1. Click the Option control in the toolbox, and then drag it onto the form, like the
one shown in Figure 15.
Option1
26
DRAFT
7. Change their properties by repeating step 3 – 5, according to the table shown
in Table 5.
8. When you have finished, your options should look like the following illustration
(Figure 16).
27
DRAFT
Adding Frame
1. Click the Frame control in the toolbox, and then drag it onto the form, like the
one shown in Figure 17.
Frame1
28
DRAFT
6. When you have finished, your options should look like the following illustration
(Figure 18).
Now you are ready to write the code for the Enviro program. Your objects
(command buttons and labels) are ready to receive input from the user and
process it automatically. However, you will need the codes that actually calculate
the installment payment and displays it in a box.
The Code window is a special window in the programming environment that you
use to enter and edit Visual Basic program statements. Inside the Code window
are program statements that mark the beginning and the end of this particular
Visual Basic subroutine, or event procedure, a block of code associated with a
particular object in the interface.
29
DRAFT
In the following steps, you will need to enter the program code for Enviro in the
Code window.
30
DRAFT
10. Repeat step 4 for Your Installment command button.
11. Type the details below between Private Sub cmdInstalment_Click() and
End Sub.
Price = Val(txtPrice.Text)
Interest = Val(txtInterest.Text)
Payment = Val(txtPayment.Text)
Else
MsgBox "Please choose your period of year", vbCritical, "Number of
year"
End If
End If
End Sub
31
DRAFT
Saving the Program
Now that you have completed the Enviro program, you should save it to disk.
To save a program in Visual Basic, click Save Project As on the File menu or
click the Save Project button on the toolbar.
1. On the File menu, click the Save Project As command. (You can save your
program at any time during the programming process.)
2. The Save File As dialog box appears, prompting you for the name and
storage location for your form.
3. Type Enviro in the File Name text box, and press Enter.
4. The form is saved under the name Enviro.frm. The Save Project As dialog
box then appears in Figure 19.
My Document
Enviro
Enviro
32
DRAFT
Run the program
1. To run a Visual Basic program from the programming environment, you can
click Start on the Run menu, click the Start button on the toolbar, or press F5.
The Enviro program runs in the programming environment. The user interface
appears, just as you designed it.
2. If Visual Basic displays an error message like the picture shown below, you
may still have a typing mistake or two in your program code. See Figure 20.
3. Try to fix it by comparing the printed version in this module with the one you
typed.
1. On the File menu, click the Make Enviro.exe command. (Visual Basic adds
your program’s name to the command automatically.) The Make Project
dialog box appears, as in Figure 21.
My Document
Enviro
Enviro
33
DRAFT
TOPIC : Documentation
LEARNING OUTCOMES :
Duration: 4 periods
READING ACTIVITY
Internal Documentation
34
DRAFT
External Documentation
WRITING ACTIVITY
Type the minimum requirements for your customer to install in your program. You
may add more specifications in the table so that your customer can run your
program smoothly.
1. Processor type
3 RAM
4 Screen Resolution
35
DRAFT
You are going to write a simple user guide here. Write the steps on teaching your
customer to install the program into his computer.
CONGRATULATIONS !!
36