Visual Basic VB: An Introduction - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Visual Basic VB: An Introduction

Description:

RAD 1 - Heriot-Watt Uni. Yussuf Abu-Shaaban - Rick Dewar 03-10-07. 12. Visual Basic (VB) ... RAD 1 - Heriot-Watt Uni. Yussuf Abu-Shaaban - Rick Dewar 03-10-07 ... – PowerPoint PPT presentation

Number of Views:32
Avg rating:5.0/5.0
Slides: 24
Provided by: rickd74
Category:

less

Transcript and Presenter's Notes

Title: Visual Basic VB: An Introduction


1
Visual Basic (VB)An Introduction
2
VB History
  • Evolved from Beginners All-purpose Symbolic
    Instruction Code (BASIC).
  • Introduced at Dartmouth College in the USA by
    Kemeney Kurtz in 1963.
  • Designed for beginners, to aid learning computer
    programming.
  • Programs execute sequentially.
  • In 1975, Bill Gates Paul Allen produced a BASIC
    version for PCs.
  • BASIC was the first product sold by the Microsoft
    corporation.

3
Cont. VB History
  • Visual BASIC was then introduced by Microsoft.
  • Aim was to enable software development under
    Windows.
  • Event-driven programming language.
  • Last version VB6, 1996.
  • No VB7.
  • Visual Basic .Net 2003, introduced as part of
    Microsofts .Net framework.
  • Object-oriented programming language.
  • Almost no backward compatibility.

4
VB is a 4GL
  • 4GLs (fourth-generation languages) are closer to
    human languages than typical high-level
    programming languages.
  • 4GLs use graphical paradigm to help developers.
  • By contrast
  • First generation machine language (0s1s).
  • Second generation assembly language
  • (LOAD 43, STORE 44).
  • Third generation high-level programming
    languages, such as C, C, and Java (xy).

5
Why VB in RAD?
  • High-level programming language, rich visual
    environment.
  • Using VB, quick prototypes can be produced to
    help elicit, refine and prioritise requirements.
  • Why not using VB for all projects
  • Portability running only on a Microsoft
    operating system.
  • Compatibility limited between versions.
  • Scalability criticised for not suiting large
    projects.

6
VB Event-Driven
  • Flow of program execution is determined by users
    actions, interacting with a Graphical User
    Interface (GUI).
  • Events can be clicks, changes in text, mouse
    movements, etc.
  • Components must programmed to response to user
    events.

7
Major Components of a VB Application
  • The whole application is called a Project.
  • Forms
  • Individual windows containing other components,
    i.e. controls
  • Controls
  • Buttons, text boxes, check boxes, list boxes,
    etc.
  • Modules - classes
  • Shared instructions, or code.
  • Provide much of the underlying functionality of
    the system using Function and Sub procedures
  • Event handlers
  • Code specific to certain components, not
    necessarily shared.
  • Enables the system to react to users actions.
  • Invoked (called) automatically by the system when
    an event occurs at the user interface.

8
VB Object-oriented
  • Most of this programming paradigm is beyond the
    scope of this module.
  • However, well mention objects briefly here.
  • Even though you wont notice it, you be
    experiencing the basic principles of OO, namely
  • Inheritance
  • Polymorphism
  • Abstraction
  • Encapsulation

9
The Notion of an Object
  • Forms, controls and some other components of a VB
    application are all types of object.
  • All these components together to constitute a
    project, from which your executable file is built
    (compiled) to create your app.
  • Objects are examples of things. Nouns if you
    like.
  • The form, apple, Yussuf Abu-Shaaban, etc.
  • An object has a type a class.
  • Apple class Fruit.
  • Yussuf class Person.
  • Objects have characteristics (called attributes
    or properties)
  • The form has a colour and a size.
  • The apple has an origin, sell by date, colour,
    weight, variety, etc.
  • Yussuf has an address, shoe size, a DoB, etc.
  • These attributes make objects unique and
    constitute their internal state.

10
An Objects Internal State
  • Different objects of the same type react in
    different ways to external circumstances,
    depending on their internal state.
  • if you are hungry and someone offers you food,
    you will probably accept
  • if you are not hungry, you will probably decline.
  • Your state of hunger determines your response to
    the external stimulus and is often different to
    your friends state.
  • For a VB application, each object (form,
    controls, etc.) behaves in different ways
    depending on the events that happen to it, its
    own internal state and the state of the rest of
    the system.
  • But what handles these events inside the object?
  • For this we need methods.

11
The Notion of Methods
  • Weve mentioned attributes/properties already as
    being part of objects
  • their size, colour, etc.
  • But we also have methods that belong to the
    object
  • If objects are things (nouns), then methods are
    actions (verbs).
  • From the human analogy, our methods are in our
    brain and help us make decisions.
  • Methods provide the objects behaviour and
    generally react to events.
  • Ask me a question and Ill reply
  • Ive got a built-in behaviour (method) that can
    make me reply when I am asked a question.
  • Click the submit button and well process your
    order
  • So we need a method to process orders after the
    click event.

12
Intermediate Recap
  • VB applications are made up of a project.
  • A project can contain various objects.
  • Objects have
  • A type (the class or family it belongs to).
  • Properties (to provide internal state).
  • Methods (to provide behaviour, e.g. change state
    or communicate with other objects).
  • Methods respond to events received by the objects.

13
Project
State
Type/Class
Properties/ attributes
Has a
Has a
Has
Receives Generates
Object
Events
Affect
Has
Respond to
Arrows imply reading order not data flow
Methods/ Behaviour
14
The VB Environment
15
The VB Environment
  • MS-Visual Studio.Net
  • Described as an IDE (Integrated Development
    Environment).
  • Handles other languages than just VB.
  • Provides a place to
  • Develop applications.
  • Debug those applications.
  • Lots of clever tools here.
  • Provides productivity enhancements.
  • Automatic completion of property and method names
  • Inline highlighting and correction of syntax
    based on context
  • Help with documentation
  • Etc.

16
Events
17
The VB Code
  • Private Sub RicksTextBox1_TextChanged(...)...
  • Me.Text RicksTextBox1.Text
  • End Sub
  • Notice the indentation!
  • Why?
  • Well look at Sub, Me, full stops, etc later.
  • The labs should give you a flavour.

18
The Result
19
Variables
  • Used to store intermediate results in your
    program.
  • The properties/attributes of objects are usually
    variables.
  • They are called variables because their values
    may vary as the program runs.
  • Each has a name which uniquely identifies it.
  • Names should begin with an alphabetic character
    and should contain only alphabetic and numeric
    characters and the underscore (_) character.
  • Store a value in each variable, and when you
    access it, it has the same value that you left
    there last time you accessed it.
  • Each time you access it, you may look at the
    value it contains, or change the value that it
    contains.

20
Declaring Variables
  • Variables should be declared before they are
    used.
  • The variable declaration specifies the name of
    the variable and its type.
  • Just like objects, variables have a type
  • The properties we mentioned earlier are generally
    variables
  • Dim x As Integer 'whole number eg 78, range
    -2147483648 to 2147483647
  • Dim cheese as Long big integer, range much
    bigger 9 x 1018
  • Dim y As String 'string of chars, eg "sdffg"
  • Dim z As Single 'floating point number eg
    45.678, range gtgt Long
  • Dim w As Double 'large floating point number,
    range gtgt Single
  • Dim t As Object 'may contain any value
  • Dim s As Boolean 'true or false
  • Others include Char, Date, Byte, etc.

21
Arithmetic Operators
  • Enable us to specify calculations which may be
    applied to data.
  • Multiply
  • / Divide
  • Mod Remainder after division
  • Add
  • - Subtract
  • Multiply, divide, and mod are performed before
    plus and minus, unless brackets are used to
    change the order.
  • x 437 would leave a value of 25 in x.
  • x (43)7 would leave a value of 49 in x.
  • x (717)/(24) would leave a value of 4 in x.
  • z 11 Mod 3 ' Returns 2.

22
Further study
  • Read and do the exercises in chapters 1, 2 and 4
    of Bell and Parrs Visual Basic .NET for
    students in the next week.
  • Remember, you should be working outside of
    timetabled classes.

23
Module Outline
Write a Comment
User Comments (0)
About PowerShow.com