Date post: | 19-Dec-2015 |
Category: |
Documents |
View: | 216 times |
Download: | 2 times |
PROBLEM SOLVING
The first step in writing instructions to carry out a task is to determine what the output should be (What should
the task produce?)
The second step is to identify the data, or input, necessary to obtain the output
The final step is to determine how to process the input to obtain the desired output
INPUT OUTPUTPROCESSING
PROGRAM DESIGN TOOLS
Flowcharts: graphically depict the logical steps to carry out a task and show how the steps relate to each other
Pseudocode: uses English-Like phrases with some (Visual Basic) terms to outline the task
Hierarchy Charts: show how the different parts of the program relate to each other (referred to as Structure Charts, HIPO (Hierarchy plus Input-Process-Output) Charts, Top-Down Charts or VTOC (Visual Table of
Contents) Charts.)
RENTING A VIDEO
START
GET CUSTOMER NUMBER
REFUSE RENTAL PROCESS
RENTAL PROCESS
GET VIDEO NUMBER
VALIDATE NUMBER
PROCESS CUSTOMER
NUMBER
END
VALIDATE NUMBER
Valid
Invalid
InvalidValid
Achieve program clarity throughStructured Programming
Event-Driven ProgrammingObject-Oriented Programming
Newer Methodologies
Event-Driven Programming - work with Events
Object-Oriented Programming - work with Objects
The internal structure of Objects and Events is best built using Structured Programming Techniques
Also, the logic of manipulating objects is occasionally best expressed with Structured Programming
What is Visual Basic?
Visual Basic (VB) is a Microsoft Windows programming language (SOFTWARE development language)
Visual Basic is derived from the BASIC (Beginners All-purpose Symbolic Instruction Code) programming
language
BASIC was developed in the mid-1960sThe widespread use of BASIC led to many
enhancements to the languageIn the late 1980s and early 1990s, with the development of the Microsoft Windows (Graphic User Interface) GUI,
the natural evolution of BASIC was Visual Basic (created by Microsoft in 1991)
VB greatly simplifies the development of Microsoft Windows-based Applications
Since 1991, 6 versions of VB have been released, with the latest Visual Basic 6 appearing in September 1998.
Microsoft provides several versions of VB, namely the Learning Edition, the Professional Edition and the
Enterprise Edition
VB programs are created in an Integrated Development Environment (IDE). The IDE allows a programmer to
create, run and debug VB programs conveniently.The process of rapidly creating an application is typically
referred to as Rapid Application Development (RAD). VB is the most widely used RAD language.
The Visual Basic Environment
In using VB you will learn to write computer programs that run in the Microsoft Windows environment
Projects will look and act like standard Windows programs
VB provides the tools you need to create windows with familiar elements like: Menus, Text Boxes,
Command Buttons, Option Buttons, Check Boxes, List Boxes, and Scroll Bars
Microsoft Windows uses a Graphic User Interface (GUI)
The Windows GUI defines how the various elements look and function
Within VB there is a Toolbox of these elements
In VB you will create new Windows called Forms
Using the toolbox to add the various elements, called Controls, to the form
VB programming is known as Event-Driven Programming
In VB you work with Objects, which have Properties and Methods
Objects: Think of an Object as a thing, or a noun
Examples of Objects are Forms and Controls
Forms are the Windows and Dialog Boxes that you place on the screen
Controls are the elements you place inside a form, such as Text Boxes, Command Buttons, and List
Boxes
Properties: Think of Properties as adjectives that describe objects
Properties tell something about an Object, such as the name, colour, size, location, and how it will
behave
When you refer to a Property[1] Name the Object [2] Name the Property
(Example: Form1.Caption)The Caption Property of the Object (Form) called
Form1
Methods: Methods are the verbs of Object-Oriented Programming
Methods are Actions associated with Objects
Example of Methods include Move, Print, Resize, and Clear
Refer to Methods as:Object.Method
(Example: Form1.Print)Sends output (Prints) to the Object (Form) called Form1
(Question: What does this Method refer to?)Printer.Print
There is a ‘Three-Step’ process in Planning and Programming a VB project
Planning[1] Design the User-Interface
[2] Plan the Properties[3] Plan the VB ‘Basic’ Code (in the planning stage
this is referred to Pseudocode)
Programming[1] Define the User-Interface
[2] Set the Properties[3] Write the VB ‘Basic’ Code
Visual Basic Project Files:
.VBP file: Project File: a small text file that contains the names of other files in the project, as well as
some information about the VB environment(release 2.0 and 3.0 of VB, .MAK extensions for
project files)
.FRM file: Form File: each form in the project is saved in a .FRM extension. Each form file holds a
description of all Objects and their Properties for the form, as well as the Basic Code written
(In VB each of these Form Files is referred to as a Form Module)
.BAS file: Standard Code Modules: hold VB ‘Basic’ statements that can be accessed from any Form
.BAS files are used in multiform projects
.OCX file: Custom Controls: additional controls/custom controls are stored in .OCX files. If
projects include controls that are not part of the Standard Control Set, then .OCX file names will be
included in the project(All controls have .OCX extensions, however, this is implicit in controls internal to the VB Environment,
and these extensions are not visible to the user)
.VBW file: after the project is saved, VB automatically adds one more file to the project, which holds
information about each of the project Forms
Project TipCreate a New Folder for a project, before creating any
files for the projectSave the .VBP file
Save the .FRM files, and Save the .BAS files into the folder
Then if the project needs to be copied or transferred from the ‘C: Drive’ to the ‘A: Drive’, all of the project
files can be transferred together within the folder, and no component parts (.VBP, .FRM, .OCX[if existing])of
the project will be lost
Component parts of a project can be lost and always save each component part separately
The VB Environment
VB Environment, where projects are created
The various windows, in the VB Environment, can be moved, resized, opened, and closed
The windows within a project can be customised
FORM
TOOLBOX
FORM WINDOW
TOOLBARMENU BAR
PROJECT EXPLORER WINDOW
FORM LOCATION & SIZE INFORMATION
PROPERTIES WINDOW
PROPERTIES HELP PANE
FORM LAYOUT WINDOW
FORM1: NAME OF THE OBJECT
FORM: CLASS OF THE OBJECT
POINTER (NOT A CONTROL)
LABEL
FRAME
DRIVELISTBOX
FILELISTBOX
LINE
DATACONTROL
CHECKBOX
COMBOBOX
HSCROLLBAR
TIMER
DIRLISTBOX
SHAPE
IMAGE
OLE
PICTUREBOX
TEXTBOX
COMMANDBUTTON
OPTIONBUTTON
LISTBOX
VSCROLLBAR
The Form Window is where the forms are designed that make up the User-Interface
Always create a ‘User-Friendly’ User-Interface
Standard windows techniques can be used to change the size and location of the form
‘Mouse-Driven Environment’
By default, a new form created in a new project, is called Form1, when the file is saved, the programmer
assigns a more meaningful name to the file(?: What is the extension?)
The Project Explorer Window holds the filenames of the files included in the project
The windows Title Bar holds the name of the project, which is Project1 by default, until saved and given a
more meaningful name (?: What is the extension?)
The Properties Window, its use relates to setting the properties for the objects in the project
Check Box 1/0, True/FalseOption Box 1/0, True/False
Command Button ‘Name’ how the computer recognises/identifies the control/object
‘Caption’ relates to the user identification of the control/object
Text Box ‘Text’ property: ‘Blank’‘Name’ property: like command button
Form Window State ‘Maximise’, relates to maximising the form when the project is executed
The Form Layout Window, this indicates the position of the form on the desktop, when the execution of the
project begins
The Toolbox holds the tools that are used to place controls on the form
The tools displayed on the toolbox, may be different, depending on the edition and release of VB being
used
‘Professional Edition’
The Main Visual Basic Window holds the VB menu bar, the toolbar, and the form location and size
information
The Toolbar, the buttons on the toolbar can be used as shortcuts for frequently used operations
Each button represents a command that can be executed by clicking on the button or by choosing a
command from the menu bar
The Form Location and Size Information identifies the size and position of the form on the screen
Help VB has an extensive ‘Help’ facility
VB contains what is called ‘Context-Sensitive’ help
Design Time, Run Time, Break Time
VB has 3 distinct modes:
Design Time: relates to designing the ‘User-Interface’ and writing code
Run Time: relates to testing and running the project
Break Time: if there is a ‘run-time error’ or project execution is paused
VB Project Example
The first ‘Event-Driven’ project will create a form with 3 controls
It will display the message ‘Hello world’ when the user clicks the ‘Push Me’ command button, and will terminate when the user clicks the ‘Exit’ command button
(Tip: If the Project Explorer Window/Properties Window/Toolbox are not displayed, open the View menu and select Project Explorer Window/Properties Window/ Toolbox
Project Tips
Do not confuse the ‘Name’ and ‘Caption’ properties
‘Name’ refers to the control in the VB code‘Caption’ refers to the users view on the form
VB sets both of these properties to the same value by default, and therefore it is easy to confuse them
NB: Always set the ‘Name’ property of controls before writing code
If the ‘Name’ of an object is changed after the code has been written, then the code becomes separated from the
object and the program does not run properly
When a VB project is running, the user can do many things
Each action by the user causes an ‘Event’ to occur in the VB project
If you write VB code for a particular event, the VB will respond to the event and automatically execute your
procedure (eg: clicking on a command button)
VB ignores events for which no procedures are written
(eg: moving the mouseresizing a window
opening another application)
VB code written in proceduresWe deal with writing code in ‘Sub Procedures’ or ‘Sub
Programs’
Begins with: Private SubEnds with: End Sub
VB automatically names the event proceudres
The ‘Name’ consists of the object name, an underscore ( _ ), and the name of the event
(name of the command button is cmdPush and there is a Click event for the command button
Therefore, the name of the Sub Procedure:
cmdPush_Click
VB Code Statements
3 types of VB statement
The Remark statement, known as comments, are used for project documentation only Begin with an
apostropheNot executable
Comments make the project more readable and understandable
The inclusion of comments is seen as good programming practice
It is a good idea to comment within the logic of the project, especially if the purpose of any statement is
unclear
The Assignment statement assigns a value to a property or variable
Assignment statements operate form Right to Left, that is the value appearing on the right hand side of the equal sign (=) is assigned to the property named
on the left of the equal sign
(Example: lblTitle.FontSize = 12Let lblTitle.FontSize = 12)
The use of ‘Let’ is optional, and its use may improve the readability of the project code
When the value to assign is ‘actual text’, known as a Literal, it is enclosed in quotation marks
This allows any combination of alpha and numeric characters to be typed
However, if the value is numeric, (eg: 12), do not enclose it in quotation marks
Do not place quotation marks around the term True or False, as VB recognises these as Special Key
Terms (Blue in colour, within VB code)
The End statement stops the execution of the project
Private Sub cmdPush_Click
‘Display the ‘Hello World’ Message
lblMessage.Caption = “Hello World”
End Sub***********************************************Private Sub cmdExit_Click
‘Exit the project
End
End Sub
Comment
Assignment