You are on page 1of 13

KEMENTERIAN PELAJARAN MALAYSIA

Self Access Learning Module


PUSAT PERKEMBANGAN KURIKULUM
KEMENTERIAN PELAJARAN MALAYSIA

IICCTT
LLiitteerraaccyy
fforr
SSeecconddaarryy
SScchooll
PPrrooggrraammee
ICTL For Secondary School --Visual Basic Express Module
1

MODULE 1
INTRODUCTION TO PROGRAMMING
Curriculum Development Centre
Ministry of Education Malaysia
ICTL For Secondary School --Visual Basic Express Module
2
1. Name of Module : Introduction to programming
2. Learning Outcomes : The students should be able to :-
a. Define programming ; and
b. State the main steps in programme development.
3. Knowledge and Skills :
a. Definition of programme ; and
b. Programming language.
4. Module Summary : At the end of the module, student should be
able to :-
a. Understand the definition of programming language.
b. Understand the phases of Program Development.
ICTL For Secondary School --Visual Basic Express Module
3
Introduction to programming
1. What is programming?
Programming refers to the act of instructing the computer to do something for us
with the help of programming language.
2. What is a programming language?
A Programming Language is a set of rules that provides a way of telling the
computer what operation to perform (according to Capron and Johnson,2004)
3. What programming languages are available?
Before looking at a specific programming language, we need to know the levels of
programming languages.
Language is said to be “lower” or “higher” depending on how close they are to the
language the computer itself uses or to the language people use (more English-likehigh).
These programming languages are generally divided into five levels or generations :-
a. Machine Language
b. Assembly Language
c. High-Level Language
d. Very High-Level Language
e. Natural Language
The following are the descriptions of each level of programming language :-
Level of language Descriptions
Machine Language
• Ultimately the computer understands
only binary number-strings of 0s and 1s.
• Programs that are written in these 0s
and 1s represent the “on” and “off”
electrical states of computer.
• All other languages must be translated
into machine language before executing
instructions.
Assembly Language
• This programming language is
considered very low level.
• This language use mnemonic codes,
abbreviations that are easy to remember
such as : A for add, C for compare, MP
for multiply and so on.
ICTL For Secondary School --Visual Basic Express Module
4
4. Examples of Programming Languages.
Examples of programming languages are :-
a. BASIC
b. COBOL
c. PASCAL
d. C
e. FORTRAN
f. VISUAL BASIC
g. C++
h. JAVA
High-Level Language
• For this language, programmers no
longer need to have detailed knowledge
of computer hardware to produce a
programme.
• This language is closer to human
language compare to the machine
language.
Very High-Level Language
• Often known as fourth generation
language(4 GLs).
• This programming language is an
improvement of high-level language.
Natural Language
• This programming language is also
called the fifth generation language.
• This language is similar to the “natural”
spoken or written English Language.
• The natural language translates human
instructions into code that the computer
can understand and execute.
ICTL For Secondary School --Visual Basic Express Module
5
Let’s look at samples of each interface for the programming languages :-
a) Example of C programming taken from
(http://encyclopedia.laborlawtalk.com/wiki/images/thumb/5/5c/500px-Qbasic.png
time) 11.20/16.6.2006.
b) Example of Visual Basic taken from (www.dmst.aueb.gr/dds/etech/swdev/env.gif)
11.20/16.6.2006
ICTL For Secondary School --Visual Basic Express Module
6
c) Example of Pascal taken from
(http://www.freedownloaddevelopment.com/delphi/pascal-look.html)
time11.20/16.6.2006.
d) Example of C programming taken from
(http://www.originlab.com/www/products/images/origin_c_code_492px.gif)
11.30/16.6.2006
ICTL For Secondary School --Visual Basic Express Module
7
e) Example of Fortran programming taken from
(http://homepage.cs.uri.edu/faculty/wolfe/book/Readings/Reading13.htm)
11:30/16.6.2006
ICTL For Secondary School --Visual Basic Express Module
8
f) Example of C++ programming taken from
(http://www.codecutter.net/tools/quincy/QscreenDump.gif)11:30/16.6.2006
g) Example of Java programming taken from
(http://ssrlibrary.ca/~megatron/images/screenshots/eclipse.png)11:30/16.6.2006
ICTL For Secondary School --Visual Basic Express Module
9
The Program Development Life Cycle
When we want to produce a program, we need to go through a few phases. There are five
main phases in program development;
Let’s look at the descriptions of each main phase in program development:
1. Problem Analysis
What is problem analysis?
You need to identify the problem before developing a program. Let’s imagine that you
are a programmer.
As a programmer, you are contacted because your services are needed. You meet
with users from the client organization to analyze the problem, or you meet with a
systems analyst who outlines the project. Specifically, the task of defining the problem
consists of identifying what it is you know (input-given data), and what it is you want to
obtain (output-the result). Eventually, you produce a written agreement that, among
other things, specifies the kind of input, processing, and output required. This is not a
simple process.
PHASE 1
Problem
Analysis
PHASE 2
PHASE 4 PHASE 3
PHASE 5
Program
Design
Coding
The problem
Testing and
Debugging
Documenting
The
Programme
ICTL For Secondary School --Visual Basic Express Module
10
2. Program Design
In this phase, you will do the following tasks :-
• Plan the solution to the problem (think about how will you solve the problem)
• Choose the interface (think about how will your program look like)
3. Coding
So now you are ready to write the code of the program that you have planned. You
need to express your solution in a programming language.
The normal process you will go through is to translate the logic from the flowchart or
pseudocode-or some other tool-to a programming language. The following are
examples of both tools:
a) Example of a flow chart
ICTL For Secondary School --Visual Basic Express Module
11
b) Example of pseudo code (that reflects the flowchart shown)
As we have already noted, a programming language is a set of rules that provides
a way of instructing the computer what operations to perform. There are many
programming languages: BASIC, COBOL, Pascal, FORTRAN, and C are some
examples. You may find yourself working with one or more of these. However in
this module, we will either produce a program using Microsoft VB-express or Just
BASIC v1.01.
Although programming languages operate grammatically, somewhat like the
English language, they are much more precise. To get your program to work, you
have to follow exactly the rules-the syntax-of the language you are using.
Of course, using the language correctly is no guarantee that your program will
work, any more than speaking grammatically correct English means you know
what you are talking about. The point is that correct use of the language is the
required first step. Then your coded program must be keyed, probably using a
terminal or personal computer, in a form the computer can understand.
One more note here: Programmers usually use a text editor, which is somewhat
like a word processing program, to create a file that contains the program.
However, as a beginner, you will probably want to write your program code on
paper first.
4. Testing and Debugging
The fourth phase is to test and debug your program.
Why do you need to test?
The imperfections of the world are still with us, so most programmers get used to the
idea that their newly written programs probably have a few errors. This is a bit
discouraging at first, since programmers tend to be precise, careful, detail-oriented
people who take pride in their work.
Still, there are many opportunities to introduce mistakes into programs, and you, just
as those who have gone before you, will probably find several of them.
sum = 0
count = 1
REPEAT
IF count is even
THEN sum = sum +
count
count = count + 1
UNTIL count > 20
DISPLAY sum
ICTL For Secondary School --Visual Basic Express Module
12
Why debug?
You need to debug to improve your program. Debug is a term used extensively in
programming. “Debugging” means detecting, locating, and correcting bugs (mistakes),
usually done by running the program.
These bugs are logic errors, such as telling a computer to repeat an operation but not
telling it how to stop repeating. In this phase you run the program using test data that
you devise. You must plan the test data carefully to make sure you test every part of
the program.
How do you debug?
You can carry out debugging by running the program. The following are examples of
debugging for Visual Basic Express and Just BASIC.
a) debugging button in Visual Basic Express
ICTL For Secondary School --Visual Basic Express Module
13
b) debugging button in Just BASIC v1.01
5. Documentation
Documentation is important when programming. Documenting is an ongoing,
necessary process, although, as many programmers are, you may be eager to
pursue more exciting computer-centered activities.
What is documentation?
Documentation is a written detailed description of the programming cycle and
specific facts about the program. Typical program documentation materials include
the origin and nature of the problem, a brief narrative description of the program,
logic tools such as flowcharts and pseudocode, data-record descriptions, program
listings, and testing results.
Comments in the program itself are also considered an essential part of
documentation. Many programmers document as they code. In a broader sense,
program documentation can be part of the documentation for an entire system.
The wise programmer continues to document the program throughout its design,
development, and testing. Documentation is needed to supplement human
memory and to help organize program planning. Also, documentation is critical to
communicate with others who have an interest in the program, especially other
programmers who may be part of a programming team.
Written documentation is needed in computer industry so that those who come
after you can make any necessary modifications in the program or track down any
errors that you missed.
ICTL For Secondary School --Visual Basic Express Module
14

MODULE 2
PROGRAMMING
VISUAL BASIC 2005 EXPRESS EDITION
( DEVELOPMENT 1 )
Curriculum Development Centre
Ministry of Education Malaysia
ICTL For Secondary School --Visual Basic Express Module
15
1. Name of module : Programming
Visual Basic 2005 Express Edition (Development 1).
2. Learning Outcomes : The students should be able to :-
a. State the features of the programming tools.
b. Identify the visual development environment of
programming tool :-
• Toolbar
• Toolbox
c. Create object using toolbox :-
• Label
• Button
• Textbox
• Picture box
3. Knowledge and Skills : Definition of programme and programming language.
4. Module Summary : At the end of the module, students should be able to
develop a simple programme.
ICTL For Secondary School --Visual Basic Express Module
16
Microsoft Visual Basic Express 2005
1. What is Microsoft Visual Basic Express 2005?
Visual Basic Express is a programming language for the Windows Operating System.
You can create various applications for your school or for your daily activities. Though
simple, it is powerful. That is why Visual Basic Express is widely used in business,
training and entertainment.
2. Why use Microsoft Visual Basic Express 2005?
Other reasons for using Microsoft Visual Basic Express 2005 are :-
• Free download
• Created standalone Window programmes are royalty free.
• Full tutorial and various examples of programmes are provided online.
• Large online community.
• Uses Graphical User Interface (GUI).
• Uses drag and drop interface designer.
• Interactive development environment.
• Easy to carry out debugging.
3. What will you produce using Microsoft Visual Basic Express 2005?
It is hoped that at the end of this lesson, you will be able to produce a simple
programme that consists of your biodata. In your programme you will learn how to
create a programme that has your photo, your particulars and how to create a user
log in that uses password. In doing so, you will experience using simple coding in
Microsoft Visual Basic Express 2005.
Getting started with Microsoft Visual Basic Express 2005
1. Click Start � Program � Microsoft Visual Basic 2005 Express Edition
• Visual Basic 2005 Express will be displayed
ICTL For Secondary School --Visual Basic Express Module
17
• Visual Basic 2005 Express window will be displayed
2. To create new project, select File � New Project
• Window Form Screen will be displayed
ICTL For Secondary School --Visual Basic Express Module
18
3. In Visual Studio installed templates select Windows Application
4. Then, name your project - Example : MyBiodata. Then click OK.
ICTL For Secondary School --Visual Basic Express Module
19
5. Form1 (shown below) developing form appears where you can draw your
application.
6. Click ToolBox on the left side of the screen and all the control will be displayed.
Then Click All Windows Forms
ICTL For Secondary School --Visual Basic Express Module
20
7. In the Toolbox, click (windows position) to uncheck AutoHide.
• Now click at the Autohide to uncheck it.
(Windows Position)
ICTL For Secondary School --Visual Basic Express Module
21
8. Click TextBox
9. Drag and drop the TextBox at the position as shown below ( Form1).
TextBox
ICTL For Secondary School --Visual Basic Express Module
22
10. To resize Textbox , click and drag the TextBox as shown below.
11. Create another three TextBox by repeating step 8 and 9.
12. Click Label in order to create four new labels.
(resize)
(move )
Label’
ICTL For Secondary School --Visual Basic Express Module
23
13. Your form should now look like this.
14. Click at the PictureBox.
PictureBox
ICTL For Secondary School --Visual Basic Express Module
24
15. Drag and drop it in the position as shown below.
16. Click the Button in order to create one button.
Button
The Position of
Picture Box
ICTL For Secondary School --Visual Basic Express Module
25
17. Now your form should look like this.
18. Click File from the menu bar and select Save al’ to save your project.
(Name : MyBiodata). Then, click Save in Save Project popup box.
ICTL For Secondary School --Visual Basic Express Module
26
19. From the Windows Properties, set properties for the Form, TextBox, Label,
PictureBox and Button. Then, rename them according to the table below.
CONTROL BOX CONTROL DEFAULT RENAME
Form1 Text
Name
Form1
Form1
MyBiodata
frmBiodata
Label1 Text Label1 Name
Label2 Text Label2 Sex
Label3 Text Label3 ICNum
Label4 Text Label4 Address
TextBox1 Name TextBox1 txtName
TextBox2 Name TextBox2 txtSex
TextBox3 Name TextBox3 txtICNum
TextBox4 Name
Multiline
TextBox4
False
txtAdd
True
Button1 Name
Text
Button1
Button1
btnExit
Exit
PictureBox1 Image Refer page 27
Windows Properties
(none)
Controls
ICTL For Secondary School --Visual Basic Express Module
27
20. To browse image (for PictureBox1) in Properties, click browse button.
21. Select Resource window will be displayed.
22. Select Local resource then click Import button.
Select resource
(browse button)
ICTL For Secondary School --Visual Basic Express Module
28
23. Now, choose an image from sample pictures folder (eg : water lilies). Click
Open then click OK.
24. In order to place the water lilies picture in the picture box, you need to click
(Picturebox Tasks) and change the size mode to “StrecthImage”
Click here to
‘StrecthImage’
ICTL For Secondary School --Visual Basic Express Module
29
25. Next, set properties for the Form MyBiodata :-
CONTROL BOX CONTROL INFORMATION
frmBiodata Backcolour ‘browse colour’ (choose colour)
txtName Text CHOO KENG FOOK
txtSex Text MALE
txtICNum Text 951031-10-1668
txtAdd Text 55, JALAN UBI, 42100 KLANG
26. Your form should now look like this and to view the coding, double click the
Exit Button to enter code mode.
ICTL For Secondary School --Visual Basic Express Module
30
27. In the Exit button code mode, type “Application.Exit()” as shown below.
28. To Run the programme, click at the menu bar or press (F5) and the
window below will be displayed.
29. Press Exit button to end your application
ICTL For Secondary School --Visual Basic Express Module
31
30. To add a new window form :-
• On the right frame, right click at MyBiodata project. Choose Add and click
Windows Form.
31. Now, your windows form will look like this. Choose the Windows Form templates
and name the form (eg : frmLogin). Then, click Add.
Click here
ICTL For Secondary School --Visual Basic Express Module
32
32. Your form will be displayed as shown below
33. Create two TextBox, two Label, one PictureBox and two Button.as shown below.
ICTL For Secondary School --Visual Basic Express Module
33
34. Set properties of the Form, two TextBox, two Labels, one PictureBox and one
Button
CONTROL
BOX CONTROL DEFAULT RENAME
frmLogin
Text
Name
Backcolour
frmLogin
frmLogin
‘browse colour’
(choose colour)
Label1 Text Label1 Name
Label2 Text Label2 Password
TextBox1 Name TextBox1 txtName
TextBox2
Name
Passwordchar
MaxLength
TextBox2
32767
txtPw
*
6
Button1 Name
Text
Button1
Button1
btnCancel
CANCEL
Button2 Name
Text
Button2
Button2
btnOK
OK
PictureBox1 Image ‘browse image’ Refer page 27
35. Your form should now look like this
ICTL For Secondary School --Visual Basic Express Module
34
36. To view the coding, double click the Cancel Button and type “Me.Close()” in the
code mode.
37. Next, click on tab ‘frmLogin.vb (Design)’. Then, click OK.
frmLogin.vb
ICTL For Secondary School --Visual Basic Express Module
35
38. To view the coding, double click the OK Button and type the content in the box.
If txtName.Text = "CHOO" And txtPw.Text = "123" Then
frmBiodata.Show()
Me.Hide()
Else
MessageBox.Show("Incorrect username or password, please try again")
End if
39. On the Menu Bar, click Project and choose MyBiodata Properties.
ICTL For Secondary School --Visual Basic Express Module
36
40. MyBiodata Properties form will be displayed. Go to Startup form then click drop
down menu and choose frmLogin.
41. To save the application, click Save all
42. To run program, click at the menu bar or press (F5) and frmLogin window
will be displayed.
43. To test the program, type name “CHOO” and type Password “123”. Then click OK.
CONGRATULATIONS !!!
YOU HAVE CREATED A PROGRAMME !!!
ICTL For Secondary School --Visual Basic Express Module
37

MODULE 3
PROGRAMMING VISUAL BASIC 2005
EXPRESS EDITION
(DEVELOPMENT 2)
Curriculum Development Centre
Ministry of Education Malaysia
ICTL For Secondary School --Visual Basic Express Module
38
1. Name of module: Programming
Visual Basic 2005 Express Edition (Development 2)
2. Learning Outcomes: The students should be able to :-
a. Declare variables
• String
• Integer
• Double
b. Write code for a simple programme.
3. Knowledge and Skills: a. Definition of programme and programming
language.
b. Able to identify the visual development
environment of programming tool.
c. Able to create object using toolbox.
4. Module Summary: At the end of the module, students should be able to
develop a simple programme.
ICTL For Secondary School --Visual Basic Express Module
39
What is Variables in programming ?
Variables contain data that stores information. The value inside may change at any
time during the course of a program. Examples of variables are integer, double and
string.
• Integer
Integer data type contains any whole number value that does not have any
fractional part. (e.g : 2, 4, 10, 1123, 3461, 275)
• Double
Any number value that may and could contain a fractional part. (e.g : 2.34, 10.54,
301.43, 8678.32)
• String
Any value that contains a sequence of number or characters. (e.g : “CHOO”,
“SUSAN”, “RM100”)
Declaring Variables
The keyword “Dim” is use to declare Variables. (Eg : Dim name as string, Dim
balance as double, Dim days as integer)
Application of Variables in programming
1. Create new project, name ‘Declaration of Variables’.
2. Create 6 Labels, 4 Textbox, 3 Buttons and 1 Picture Box. Your form should look
like this.
ICTL For Secondary School --Visual Basic Express Module
40
3. Change the properties of the Control Box based on the following table.
4. Your form should look like this.
CONTROL BOX CONTROL DEFAULT RENAME
Name Form 1 frmSaving
Form 1 BacTkeCxot lor ‘browTsee xcto lour’ My Savings
(Choose colour)
Name Label1 lblTitle
Label 1 Text Label1 HOW MUCH CAN I
SAVE ?
Label 2 NTaemxte LLaabbeell22 NlbalNmaem e
Name Label3 lblBalance
Label 3 Text Label3 Balance Per Day
(RM)
Label 4 NTaemxte LLaabbeell44 lDbalDyasy s
Label 5 NTaemxte LLaabbeell55 TlbolTtaolt a (lR M)
Name Label6 lblNotice
Label 6 Text Label6
AutoSize True False
TextBox1 Name TextBox1 txtName
TextBox2 Name TextBox2 txtBalance
TextBox3 Name TextBox3 txtDays
TextBox4 ReNaadmOen ly TeFxatblsoex 4 tTxrtuTeo tal
Button 1 NTaemxte BBuuttttoonn11 bCtOnCUoNuTn t
Button 2 NTaemxte BBuuttttoonn22 RbtEnSREesTe t
Button 3 NTaemxte BBuuttttoonn33 EbtXnIETx it
PictureBox1 Image ‘browse image’
(Choose image)
ICTL For Secondary School --Visual Basic Express Module
41
5. To save the application, click File and select Save all.
6. To view the coding, double click anywhere on the form.
Public Class frmSaving
Dim Name As String
Dim Balance As Double
Dim Days As Integer
Dim Total As Double
Private Sub frmSaving_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
End Sub
End Class
7. Click on the tab Form1.vb[Design]*.
8. Double click on COUNT button and type the following :-
Private Sub btnCount_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnCount.Click
Name = (txtName.Text)
Balance = Val(txtBalance.Text)
Days = Val(txtDays.Text)
Total = Balance * Days
txtTotal.Text = Total
lblNotice.Text = Name & " your total saving for " & days & " days is RM " & total
End Sub
Type the following syntax
Click here
Type the following syntax
ICTL For Secondary School --Visual Basic Express Module
42
9. Click on the Form1.vb[Design]* tab as in step 7.
10. Double click on RESET button and type the following.
Private Sub btnReset_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnReset.Click
txtName.Text = " "
txtBalance.Text = " "
txtDays.Text = " "
txtTotal.Text = " "
End Sub
11. Click on the Form1.vb[Design]* tab as in step 7.
12. Double click on EXIT button and type “Me.Close()”
13. To save the application, click File and select ‘ Save all’
14. To Run program, click / (F5) and frmSaving window will be displayed.
Type the following syntax
ICTL For Secondary School --Visual Basic Express Module
43
15. To test the program, type :-
Name : Choo
Balance Per Day (RM) : 124.35
Days : 3
and click COUNT.
CONGRATULATIONS !!!
TASK ACCOMPLISHED !!!

You might also like