Chapter 31 Fundamentals of Programming in Visual Basic (VB) Visual Basic Events Simple Statement.
Introduction to Visual Basic Programming. Lecture Outline History What is Visual Basic First Look at...
-
date post
19-Dec-2015 -
Category
Documents
-
view
237 -
download
1
Transcript of Introduction to Visual Basic Programming. Lecture Outline History What is Visual Basic First Look at...
Lecture Outline
• History• What is Visual Basic• First Look at the VB 6.0 Environment• Some VB Terminology• Our first VB Program
BASIC• BASIC (Beginner's All-purpose Symbolic Instruction
Code) • Designed in 1964, by Kemeny and Kurtz at Dartmouth • Goal was to provide access for non-science students to
computers. • Back then all use of computers required writing
custom software– But only Computer Scientists/Mathematicians did this
• Language became widespread on microcomputers in the late 1970s and home computers in the 1980s.
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
Between 1991 and 1998 6 versions of VB were released, with 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
The Initial Visual Basic Screen
Toolbox
Project Explorerwindow
Properties window
Form
Menu bar
Description pane
Form Layout window
Toolbar
Project Container window
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
Steps to Create a Visual Basic Program
1. Create the interface by placing controls on the form
2. Set properties for the controls and the form3. Write code for event procedures associated
with the controls and the form
Placing a Text Box on a Form
• Double-click on the text box icon in the toolbox to add a text box to your form
• Activate the properties window (Press F4)• Set values of properties for text box
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
Naming Objects:Object Prefix Example
Command Button cmd cmdStart
Form frm frmPayroll
Label lbl lblName
Picture box pic picClouds
Text box txt txtAddress
Visual Basic Events
• Code is a set of statements that instruct the computer to carry out a task.
• Code can be associated with events • When an event occurs, the code associated
with that event (called an Event Procedure) is executed.
Creating An Event Procedure• Double-click on an object to open a Code
window. (The empty default event procedure will appear. Click on the Procedure box if you want to display a different event procedure.)
• Write the code for that event procedure.
Example of An Event Procedure
Private Sub objectName_event ( ) statementsEnd Sub
Private Sub txtOne_GotFocus( ) txtOne.Font.Size = 12 txtOne.Font.Bold = FalseEnd Sub