Professional Documents
Culture Documents
Module 1-3 - VB Express
Module 1-3 - VB Express
MODULE 1
INTRODUCTION TO PROGRAMMING
1.
Name of Module
: Introduction to programming
2.
Learning Outcomes
3.
4.
Module Summary
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.
Machine Language
Assembly Language
High-Level Language
Very High-Level Language
Natural Language
The following are the descriptions of each level of programming language :Level of language
Descriptions
Machine Language
Assembly Language
High-Level Language
Natural Language
VISUAL BASIC
g. C++
h. JAVA
Lets 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.
f)
PHASE 1
Problem
Analysis
PHASE 5
PHASE 2
Documenting
The
Programme
Program
Design
PHASE 4
PHASE 3
Testing and
Debugging
Coding
The problem
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
10
11
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
12
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.
13
MODULE 2
PROGRAMMING
VISUAL BASIC 2005 EXPRESS EDITION
( DEVELOPMENT 1 )
14
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
4. Module Summary
15
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
17
18
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
(Windows Position)
20
8. Click TextBox
9. Drag and drop the TextBox at the position as shown below ( Form1).
TextBox
21
10. To resize Textbox , click and drag the TextBox as shown below.
(resize)
(move )
Label
22
PictureBox
23
The Position of
Picture Box
Button
24
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
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
CONTROL BOX
Form1
Label1
Label2
Label3
Label4
TextBox1
TextBox2
TextBox3
TextBox4
Button1
PictureBox1
CONTROL
Text
Name
Text
Text
Text
Text
Name
Name
Name
Name
Multiline
Name
Text
Image
26
DEFAULT
Form1
Form1
Label1
Label2
Label3
Label4
TextBox1
TextBox2
TextBox3
TextBox4
False
Button1
Button1
RENAME
MyBiodata
frmBiodata
Name
Sex
ICNum
Address
txtName
txtSex
txtICNum
txtAdd
True
btnExit
Exit
(none)
Refer page 27
Select resource
(browse button)
27
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
25. Next, set properties for the Form MyBiodata :CONTROL BOX
CONTROL
INFORMATION
frmBiodata
Backcolour
txtName
Text
txtSex
Text
MALE
txtICNum
Text
951031-10-1668
txtAdd
Text
26. Your form should now look like this and to view the coding, double click the
Exit Button to enter code mode.
29
27. In the Exit button code mode, type Application.Exit() as shown below.
30
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
33. Create two TextBox, two Label, one PictureBox and two Button.as shown below.
32
34. Set properties of the Form, two TextBox, two Labels, one PictureBox and one
Button
CONTROL
BOX
frmLogin
Label1
Label2
TextBox1
TextBox2
Button1
Button2
PictureBox1
CONTROL
DEFAULT
Text
Name
Backcolour
frmLogin
frmLogin
browse colour
(choose colour)
Label1
Label2
TextBox1
TextBox2
Text
Text
Name
Name
Passwordchar
MaxLength
Name
Text
Name
Text
Image
32767
Button1
Button1
Button2
Button2
browse image
33
RENAME
Name
Password
txtName
txtPw
*
6
btnCancel
CANCEL
btnOK
OK
Refer page 27
36. To view the coding, double click the Cancel Button and type Me.Close() in the
code mode.
34
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.
35
40. MyBiodata Properties form will be displayed. Go to Startup form then click drop
down menu
and choose frmLogin.
43. To test the program, type name CHOO and type Password 123. Then click OK.
CONGRATULATIONS !!!
YOU HAVE CREATED A PROGRAMME !!!
36
MODULE 3
37
1. Name of module:
Programming
Visual Basic 2005 Express Edition (Development 2)
2. Learning Outcomes:
4. Module Summary:
38
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)
39
3. Change the properties of the Control Box based on the following table.
CONTROL BOX
Form 1
Label 1
Label 2
Label 3
Label 4
Label 5
Label 6
TextBox1
TextBox2
TextBox3
TextBox4
Button 1
Button 2
Button 3
PictureBox1
CONTROL
DEFAULT
Name
Text
BackColor
Name
Text
Form 1
Text
browse colour
(Choose colour)
Label1
Label1
Name
Text
Name
Text
Label2
Label2
Label3
Label3
Name
Text
Name
Text
Name
Text
AutoSize
Name
Name
Name
Name
ReadOnly
Name
Text
Name
Text
Name
Text
Image
Label4
Label4
Label5
Label5
Label6
Label6
True
TextBox1
TextBox2
TextBox3
Textbox4
False
Button1
Button1
Button2
Button2
Button3
Button3
browse image
(Choose image)
40
RENAME
frmSaving
My Savings
lblTitle
HOW MUCH CAN I
SAVE ?
lblName
Name
lblBalance
Balance Per Day
(RM)
lblDays
Days
lblTotal
Total (RM)
lblNotice
False
txtName
txtBalance
txtDays
txtTotal
True
btnCount
COUNT
btnReset
RESET
btnExit
EXIT
Click here
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)
Type the following syntax
Days = Val(txtDays.Text)
Total = Balance * Days
txtTotal.Text = Total
lblNotice.Text = Name & " your total saving for " & days & " days is RM " & total
End Sub
41
42
: Choo
: 124.35
Days
:3
CONGRATULATIONS !!!
TASK ACCOMPLISHED !!!
43