Академический Документы
Профессиональный Документы
Культура Документы
MODULE 1
INTRODUCTION TO PROGRAMMING
1
ICTL For Secondary School --Visual Basic Express Module
b. Programming language.
2
ICTL For Secondary School --Visual Basic Express Module
Introduction to programming
1. What is programming?
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-like-
high).
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
3
ICTL For Secondary School --Visual Basic Express Module
a. BASIC
b. COBOL
c. PASCAL
d. C
e. FORTRAN
f. VISUAL BASIC
g. C++
h. JAVA
4
ICTL For Secondary School --Visual Basic Express Module
5
ICTL For Secondary School --Visual Basic Express Module
6
ICTL For Secondary School --Visual Basic Express Module
7
ICTL For Secondary School --Visual Basic Express Module
8
ICTL For Secondary School --Visual Basic Express Module
When we want to produce a program, we need to go through a few phases. There are five
main phases in program development;
PHASE 1
Problem
Analysis
PHASE 5 PHASE 2
Documenting Program
The Design
Programme
PHASE 4 PHASE 3
1. 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.
9
ICTL For Secondary School --Visual Basic Express Module
2. Program Design
• 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:
10
ICTL For Secondary School --Visual Basic Express Module
sum = 0
count = 1
REPEAT
IF count is even
THEN sum = sum +
count
count = count + 1
UNTIL count > 20
DISPLAY sum
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.
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.
11
ICTL For Secondary School --Visual Basic Express Module
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.
You can carry out debugging by running the program. The following are examples of
debugging for Visual Basic Express and Just BASIC.
12
ICTL For Secondary School --Visual Basic Express Module
5. Documentation
What is documentation?
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.
13
ICTL For Secondary School --Visual Basic Express Module
MODULE 2
PROGRAMMING
VISUAL BASIC 2005 EXPRESS EDITION
( DEVELOPMENT 1 )
14
ICTL For Secondary School --Visual Basic Express Module
15
ICTL For Secondary School --Visual Basic Express Module
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.
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.
16
ICTL For Secondary School --Visual Basic Express Module
17
ICTL For Secondary School --Visual Basic Express Module
18
ICTL For Secondary School --Visual Basic Express Module
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
19
ICTL For Secondary School --Visual Basic Express Module
(Windows Position)
20
ICTL For Secondary School --Visual Basic Express Module
8. Click TextBox
9. Drag and drop the TextBox at the position as shown below ( Form1).
TextBox
21
ICTL For Secondary School --Visual Basic Express Module
10. To resize Textbox , click and drag the TextBox as shown below.
(resize)
(move )
Label’
22
ICTL For Secondary School --Visual Basic Express Module
PictureBox
23
ICTL For Secondary School --Visual Basic Express Module
The Position of
Picture Box
Button
24
ICTL For Secondary School --Visual Basic Express Module
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.
25
ICTL For Secondary School --Visual Basic Express Module
19. From the Windows Properties, set properties for the Form, TextBox, Label,
PictureBox and Button. Then, rename them according to the table below.
Windows Properties
Controls
26
ICTL For Secondary School --Visual Basic Express Module
Select resource
(browse button)
27
ICTL For Secondary School --Visual Basic Express Module
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’
28
ICTL For Secondary School --Visual Basic Express Module
26. Your form should now look like this and to view the coding, double click the
Exit Button to enter code mode.
29
ICTL For Secondary School --Visual Basic Express Module
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.
30
ICTL For Secondary School --Visual Basic Express Module
• On the right frame, right click at MyBiodata project. Choose Add and click
Windows Form.
Click here
31. Now, your windows form will look like this. Choose the Windows Form templates
and name the form (eg : frmLogin). Then, click Add.
31
ICTL For Secondary School --Visual Basic Express Module
33. Create two TextBox, two Label, one PictureBox and two Button.as shown below.
32
ICTL For Secondary School --Visual Basic Express Module
34. Set properties of the Form, two TextBox, two Labels, one PictureBox and one
Button
CONTROL
CONTROL DEFAULT RENAME
BOX
Text frmLogin
Name frmLogin
frmLogin
Backcolour ‘browse colour’
(choose colour)
Label1 Text Label1 Name
Label2 Text Label2 Password
TextBox1 Name TextBox1 txtName
Name TextBox2 txtPw
TextBox2 Passwordchar *
MaxLength 32767 6
Name Button1 btnCancel
Button1
Text Button1 CANCEL
Name Button2 btnOK
Button2
Text Button2 OK
PictureBox1 Image ‘browse image’ Refer page 27
33
ICTL For Secondary School --Visual Basic Express Module
36. To view the coding, double click the Cancel Button and type “Me.Close()” in the
code mode.
frmLogin.vb
34
ICTL For Secondary School --Visual Basic Express Module
38. To view the coding, double click the OK Button and type the content in the box.
39. On the Menu Bar, click Project and choose MyBiodata Properties.
35
ICTL For Secondary School --Visual Basic Express Module
40. MyBiodata Properties form will be displayed. Go to Startup form then click drop
down menu and choose frmLogin.
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 !!!
36
ICTL For Secondary School --Visual Basic Express Module
MODULE 3
37
ICTL For Secondary School --Visual Basic Express Module
a. Declare variables
• String
• Integer
• Double
38
ICTL For Secondary School --Visual Basic Express Module
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)
2. Create 6 Labels, 4 Textbox, 3 Buttons and 1 Picture Box. Your form should look
like this.
39
ICTL For Secondary School --Visual Basic Express Module
3. Change the properties of the Control Box based on the following table.
40
ICTL For Secondary School --Visual Basic Express Module
End Sub
End Class
Click here
Name = (txtName.Text)
Balance = Val(txtBalance.Text)
Days = Val(txtDays.Text) Type the following syntax
Total = Balance * Days
txtTotal.Text = Total
lblNotice.Text = Name & " your total saving for " & days & " days is RM " & total
End Sub
41
ICTL For Secondary School --Visual Basic Express Module
13. To save the application, click File and select ‘ Save all’
14. To Run program, click / (F5) and frmSaving window will be displayed.
42
ICTL For Secondary School --Visual Basic Express Module
Name : Choo
Days :3
CONGRATULATIONS !!!
TASK ACCOMPLISHED !!!
43