Sie sind auf Seite 1von 41

Chapter One

1
INTRODUCTION TO VISUAL BASIC PROGRAMMING

BY : RAZIF MUSTAPHA

F 3005 VISUAL BASIC PROGRAMMING

Learning Objectives
2

By the end of the class, students should be able to :


Explain the editions of VB. Define event driven programming.

Differentiate structured and event-driven programming

F 3005 VISUAL BASIC PROGRAMMING

Intoduction Visual Programming language


3

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 textbased programming, text is still being used in visual programming.
F 3005 VISUAL BASIC PROGRAMMING

Visual Programming language


4

Text is used in:


Documentation

Naming objects that differentiate elements of the

same type Writing program code (event, method)

F 3005 VISUAL BASIC PROGRAMMING

Visual Programming language


5

Example: Visual objects with the addition and subtraction functions that will receive 2 numbers as the input to generate one output.

Diagram 1.1
F 3005 VISUAL BASIC PROGRAMMING

Introduction to one type of VPL: Visual Basic


6

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.

F 3005 VISUAL BASIC PROGRAMMING

Introduction To Visual Basic


7

Definition

Visual Basic is derived from 2 words:

VISUAL + BASIC

F 3005 VISUAL BASIC PROGRAMMING

Visual
8

VISUAL Is a method to design graphical user interface. You dont 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.

Diagram 1.2: Example of a Graphical User Interface


F 3005 VISUAL BASIC PROGRAMMING

Basic
9

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).
You did it!

CLS PRINT You did it! PRINT PRINT You are now a programmer.

You are now a programmer.

Program code in BASIC

Program output

Example of BASIC Program


F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
10

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).

F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
11

Interface produced with VB code

Code window, for the even Change

Diagram 1.3: User Interface with VB code


F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
12

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.
F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
13

F 3005 VISUAL BASIC PROGRAMMING

Diagram 1.4: Visual Basic Interface

History of Visual Basic


14
It's a computer programming system developed and owned by Microsoft. Visual Basic evolved from BASIC (Beginners All-Purpose Symbolic

Instruction Code).
Year 1960s Description John Kemeny and Thomas Kurtz at Dartmouth College developed BASIC (Beginners All-Purpose Symbolic Instruction Code). Many versions of BASIC were developed, including MS-BASIC and QuickBASIC (Qbasic). Microsoft Corporation has developed Visual Basic as a Windows application designed to assist programmers in developing other event-driven Windows applications. The 6th Version of Visual Basic was launched. Microsoft introduced Visual Basic .NET 1.0

Late 1980s

1991

September 1998 2002

F 3005 VISUAL BASIC PROGRAMMING

History of Visual Basic


15

Thomas Kurtz

John G. Kemeny

Founders of the programming language BASIC


F 3005 VISUAL BASIC PROGRAMMING

Edition of Visual basic


16

Microsoft Visual basic comes in several varieties : Learning Edition

Professional Edition
Enterprise Edition

F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
17

Advantages of using Visual Basic


Component Tools Advantage 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.

F 3005 VISUAL BASIC PROGRAMMING

VISUAL BASIC
18

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.
The concept covers - windows, events, messages,

objects, user interface, controls and application.


F 3005 VISUAL BASIC PROGRAMMING

Object-Oriented Event-driven Programming (OOED)


19

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.
F 3005 VISUAL BASIC PROGRAMMING

Object-Oriented Event-driven Programming (OOED)


20

Visual Basic is an OOED language. OOED is easier to work with, because it is more intuitive

than traditional programming methods.

In the traditional procedural applications, it is the code that

controls the application to produce an output.


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.
F 3005 VISUAL BASIC PROGRAMMING

OOED
21

Diagram 1.5: Example of an event, triggered when user clicks the command button, Done
F 3005 VISUAL BASIC PROGRAMMING

Message
22

Each time an event is triggered, a message is sent to

the operating system. The system will process the message and display the output in a different window.
Each window can take necessary action based on its

own instruction to handle specific messages (example: changing the color of the window when closing another window).

F 3005 VISUAL BASIC PROGRAMMING

Message
23

View on how the operating system handles an event

F 3005 VISUAL BASIC PROGRAMMING

Objects
24

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

objects name will begin with three-lettered prefix that signifies the type of the object.

F 3005 VISUAL BASIC PROGRAMMING

Objects
25

Object Oriented Programming (OOP) is a complex technology.

Programmers who are new to object technology should view OOP as an important, new computer-programming paradigm.
Decision about application design are made before programming (or

construction) even begins.


Object Oriented Programming (OOP) is the process of developing one-

to-many lines of programming instructions based on well-defined design models. Such design models are graphical illustrations that represent different aspects of objects, those objects classes (from which they derive functions and property variables), and their interactions with each other.

F 3005 VISUAL BASIC PROGRAMMING

Objects
26

Prefix lbl frm cmd txt Label Form

Object

Example lblName, lblTitle frmCalculator cmdPress txtNumber,txtAddress

Command Buttons TextBox

F 3005 VISUAL BASIC PROGRAMMING

Methods and Properties


27

Action associated with object are called methods. Methods are the verbs of object-oriented

programming. Some typical methods are Move, Print, Resize, Clear etc. Properties tell something about an object, such as its name, color, size, font or how it will behave.

F 3005 VISUAL BASIC PROGRAMMING

Structured And Event-Driven Programming


28

QBASIC

Visual Basic

DOS based

Window based

Requires long lines of codes to Programs are written with the involvement of mouse clicks, oncreate a program screen buttons and drag & drop tools.
QBASIC is a translator, eases testing Visual Basic requires a compiler but difficult to distribute and protect unless you have a separate compiler. QBASIC can never be developed for Large program size with visual bigger programs because it is only effects and GUI can be limited to 0.16MB of memory. It has developed. no visual displays.
F 3005 VISUAL BASIC PROGRAMMING

Program Structure Of Visual Basic


29

Private Sub Event for an object Variable declaration Any VB statements Note Event for an object End Sub oEvents 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 oComprise functions, methods, comments and procedures.

F 3005 VISUAL BASIC PROGRAMMING

Break!

Visual Programmed Design And Development


31

There are three steps in order to build an application known as

three-step-process which enables application to be developed in a simple and standard form.


Creating the interface Phase 1

Setting properties

Phase 2

Writing code

Phase 3

F 3005 VISUAL BASIC PROGRAMMING

Getting Started with Visual Basic


32

Double-click VB icon on Desktop or use Start /

Programs / Visual Basic to bring up opening dialog box

F 3005 VISUAL BASIC PROGRAMMING

VB Development Environment
33

IDE: Integrated Development Environment Document Interface :

- MDI: Multiple Document Interface - SDI : Single Document Interface

F 3005 VISUAL BASIC PROGRAMMING

MDI and SDI


34

What is the difference between MDI and SDI?

SDI Independent Windows on the desktop. Suitable for windows with low resolution.

MDI Window within a window on the desktop. Suitable for windows with higher resolution.

You should start in the default MDI environment. Project Window should have a white background. Form Window is shown as part of a larger Project Window.
F 3005 VISUAL BASIC PROGRAMMING

VB Development Environment
35

Initial size of form is 4800 x 3600

twips.
1440

twips is 1 inch, when printed. 120 twips is the distance between dots on the grid

F 3005 VISUAL BASIC PROGRAMMING

VB Development Environment
36 Toolbar

Initial Form Window Project Explorer Toolbox

Project Window

Properties Window Form Layout Window Sizing Handles

F 3005 VISUAL BASIC PROGRAMMING

VB Development Environment
37

1. Form a window in which the application is designed. 2. Toolbox for drawing controls on the form 3. Project Explorer a list of any forms and other types of files in the project 4. Properties Window a list of the property settings for a particular control

F 3005 VISUAL BASIC PROGRAMMING

Visual Basic Menu Bar


38

The menu bar has drop-down menus from which you control the operation of the Visual Basic environment. It has buttons that provide shortcuts to some of the menu options. It also shows the location of the current form relative to the upper left corner of the screen (measured in twips) and the width and length of the current form.

F 3005 VISUAL BASIC PROGRAMMING

Visual Basic Tool Box


39

F 3005 VISUAL BASIC PROGRAMMING

Project Explorer Window


40

Used to select the code or object or to change folders.


F 3005 VISUAL BASIC PROGRAMMING

Lets Start Your Activity 1

Das könnte Ihnen auch gefallen