Upload
ngotuyen
View
218
Download
3
Embed Size (px)
Citation preview
UNIT 1INTRODUCTION TO
VISUAL PROGRAMMING AND VB
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
At the end of this chapter, the students should be able to:
Explain what is Visual Programming Language (VPL)
Understand the history of VPL
Learn a type of VPL: Visual Basic (VB)
o Definition
o Usage
o History
o Advantages
o Concept
o Examples
o Program Structure
Objectives
1.1 What is Visual Programming Language (VPL)?
It is a programming language that uses visual techniques to illustrate the relationship between
data or the changes to the data.
Despite the fact that the visual communication in VPL is higher compared to the traditional
text-based programming, text is still being used in visual programming.
Text is used in:
o Documentation
o Naming objects that
differentiate elements of
the same type
o Writing program code
(event, method)
2
Note:Visual Technique: Includes sketching,
pointing, and instant
demonstration of any
manipulation carried out
on an object directly.
Example:Visual objects with the addition and subtraction
functions that will receive 2 numbers as the input to
generate one output.
Diagram 1.1
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
1.2 History of VPL
Combination of graphic computer + programming language + user interface
Year Description
1963
Ivan Sutherland – Created the Sketchpad system using the TX-2 computer at MIT.
The best example of the first computer graphic application.
The system allows user to use lightpen to design 2D graphic such as circle, line and
other operation such as copy.
1965
William Sutherland – developed the simple visual data flow language.
Develop menu system that can create, debug and run DFD in an integrated visual
environment.
1975
David Canfield Smith – completed his PHD with the title “Pygmalion: A Creative
Programming Environment”.
His work became the starting point to researches until today.
Paradigm of icon-based programming exists due to Pygmalion.
Table 1.1
1.3 Introduction to one type of VPL: Visual Basic
High Level Programming Language – developed from a DOS version; BASIC.
Easy to learn and the code are English-like statements.
The programming language is Visual based and is based on event.
1.3.1 Definition
Visual Basic is derived from 2 words:
Visual & Basic
We will look at the meaning of each word and the meaning of both words when combined.
VISUAL
Is a method to design graphical user interface.
You don’t need to write lines of codes to display the position of your objects just click and
drag to place the object at a suitable position on the screen.
3
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
Diagram 1.2: Example of a Graphical User Interface
BASIC
Based on the BASIC (Beginners All-Purpose Symbolic Instruction Code), a language that is
commonly used by most programmers compared to other traditional programming languages
(e.g. FORTRAN).
VISUAL BASIC
Evolved from the original BASIC language and now contains hundreds of statement,
functions and keywords. Visual Basic is also a method to create Graphic User Interface,
(GUI).
4
CLSPRINT “You did it!”PRINT PRINT “You are now a programmer.”
You did it!
You are now a programmer.
Example of BASIC Program Output produced
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
Diagram 1.3: User Interface with VB code
1.3.2 What is the function of Visual Basic?
Enable programmers to build average-sized applications with suitable GUIs quickly.
Enable a quick application development or Rapid Application Development –RAD software.
Examples of programming languages with RAD feature: Borland Delphi, Borland C++
Builder, Microsoft J++, Microsoft Visual Basic, etc.
Diagram 1.4: Visual Basic Interface
5
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
1.3.3 History of Visual Basic
Visual Basic evolved from BASIC (Beginners All-Purpose Symbolic Instruction Code).Year Description
1960s John Kemeny and Thomas Kurtz at Dartmouth College developed BASIC
to write simple program.
The usage was on multiple platforms.
The main aim: to help individual learn to write a program.
Late 1980s Many versions of BASIC were developed, including MS-BASIC and
QuickBASIC (Qbasic).
1991 Microsoft Corporation has developed Visual Basic as a Windows
application designed to assist programmers in developing other event-
driven Windows applications.
September
1998
The 6th Version of Visual Basic has been launched.
Table 1.2
Diagram 1.5: Founders of the BASIC programming language
1.3.4 Difference between QBASIC and Visual Basic
QBASIC Visual Basic
DOS based Windows based
Requires long lines of codes to create a program Programs are easily written because it involves
mouse clicks on-screen buttons and drag &
drop tools.
QBASIC is a translator, easy to be tested but it is
difficult to be distributed and to be protected
unless you have a separate compiler.
Visual Basic requires a compiler
It is impossible to create bigger program with
QBASIC because its memory can only retrieve
not more than 0.16MB data. It is hard to create
visual effect using this language.
Large sized program with visual effects can be
developed easily because the program
development uses Microsoft Windows
graphical user interface (GUI).
Table 1.3
6
Thomas Kurtz John G. Kemeny
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
1.3.5 Advantages of using Visual Basic
Component Advantage
Tools Enables the development of small application for individual users, large
organisations and internet applications.
Data Access Create front-end applications with database and server access. (E.g.
SQL Server)
Internet Support Easy to retrieve documents and applications via the Internet or Intranet.
Active X Technology Allow integration with different applications.
Example: Microsoft Word Processor, Microsoft Excel.
Table 1.4
1.4 Visual Basic Concept
It combines the facilities in Basic Language and visual interface in order to help you in
creating interface and code for an application easily.
It is built in the Windows environment and deals with objects.
1.4.1 Understanding the Event-Driven Model
In the traditional procedural applications, it is the application that controls all the codes to be
executed in its sequence.
In the process of execution, the first line of code is being read and based on the instructions
from each line of code, it will trigger the necessary procedures.
In an event-driven application, codes do not go through a fixed direction. Codes are activated
based on an event, triggered by user action through messages from the system or another
application or the local application.
7
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
Diagram 1.6: Visual Basic Interface
Diagram 1.7: Example of an event, triggered when user clicks the command button, Done
8
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
1.4.2 Objects
VB deals with objects, which refer to ‘things’. Examples of objects in VB are form, textbox
and command button.
Each object in VB has its own characteristics or attributes called properties. Examples of
properties in VB are Caption and BackColor.
Objects can also carry out some actions such as Hide and Show.
Each object in VB has a unique and meaningful name. Usually an object’s name will begin
with three-lettered prefix that signifies the type of the object.
Prefix Object Example
lbl Label lblName, lblTitle
frm Form frmCalculator
cmd Command Buttons cmdPress
txt TextBox txtNumber,txtAddress
Table 1.6
1.5 Example of Program
This is an example of a program that carries out 2 operations; addition and subtraction.
Diagram 1.8: Application Interface
Program Code
9
‘Declare 2 variables of type integerDim num1 As Integer, num2 As Integer
‘Add two numbersPrivate Sub cmdAdd_Click()num1 = txtNum1.textnum2 = txtNum2.texttxtAdd.text = num1 + num2End Sub
‘Subtract two numbersPrivate Sub cmdSubtract_Click()num1 = txtNum1.textnum2 = txtNum2.texttxtAdd.text = num1- num2End Sub
UNIT 1: INTRODUCTION TO VISUAL PROGRAMMING & VBF3005: VISUAL BASIC PROGRAMMING
1.5.1 Program Structure
10
Private Sub Event for an object Variable declaration
Any VB statements
End Sub
Note Event for an object
o Events can occur through user actions
such as a mouse click or a key press,
through programmatic control, or
even as a result of another window's
actions, e.g. Command1_Click ()
Visual Basic program statement
o Comprise functions, methods,
comments and procedures.