Title: Visual Basic
1Visual Basic
- Visual Basic is an Object Oriented
Programming language
2Visual Basic
- Much, Much, Much, Much less effort required
to produce a usable program than procedural
programming languages - Lets all say Hurrah
3Visual Basic
- As Visual Basic programmer, you will use Visual
Studio to create - Objects
- Events
4More about Objects
- VB uses MANY objects
- One category of objects is referred to as
controls - You are quite familiar with controls
5Visual Basic Controls
- As a Windows user youre already familiar with
many Visual Basic controls - Label - displays text the user cannot change
- TextBox - allows the user to enter text
- Button performs an action when clicked
- RadioButton - A round button that is selected or
deselected with a mouse click - CheckBox A box that is checked or unchecked
with a mouse click - Form - A window that contains these controls
6Many Control Objects Here
- Some objects on the formare classified as
controls - This form has
- Two TextBox controls
- Four Label controls
- Two Button controls
- Buttons have methods attached to click events
7First Lab
- Tutorial 1-3 demonstrates Control object
- Do Tutorial 1-3
- Turn to page 10 of textbook
- Navigate to my handouts directory
L\handouts\schabetc - Once there, continue tutorial 1-3 with step 2
- Chaos and Mayhem ensues
8More on Events
- The Object Oriented Programs are said to be
event-driven - An event is an action that takes place within a
program - Clicking a button (a Click event)
- Keying in a TextBox (a TextChanged event)
- A program can respond to an event if the
programmer writes an event procedure
9Event ProcedureCompute Gross Pay
Private Sub btnCalcGrossPay_Click(ByVal sender As
System.Object, _ ByVal e As System.EventArgs)
Handles btnCalcGrossPay.Click Define a
variable to hold the gross pay. Dim sngGrossPay
As Single Convert the values in the text boxes
to numbers, and calculate the gross
pay. sngGrossPay CSng(txtHoursWorked.Text)
CSng(txtPayRate.Text) Format the gross pay for
currency display and assign it to the Text
property of a label. lblGrossPay.Text
FormatCurrency(sngGrossPay) End Sub
10Event ProcedureClose
Private Sub btnClose_Click(ByVal sender As
System.Object, _ ByVal e As System.EventArgs)
Handles btnClose.Click End the program by
closing its window. Me.Close() End Sub
11Time out for DefinitionGUI
- GUI - Graphical User Interface A phrase used to
describe a windows environment where the user
of a program uses a mouse and keyboard to
interface with the program.
12Example of a GUI
13Example GUI
Enter number of hours worked _
14Example GUI
Enter number of hours worked 10
15Example GUI
Enter number of hours worked 10 Enter hourly
pay rate _
16Example GUI
Enter number of hours worked 10 Enter hourly
pay rate 15
17Example GUI
Enter number of hours worked 10 Enter hourly
pay rate 15 Gross pay is 150.00
18Time out for definitionProperty
- The attributes of an object.This definition
presupposes that you know what attribute
means.Attribute is often used instead of the
more formal term, property - All controls have properties
- Each property has a value
- Values are assigned by the programmer if s/he
doesnt want the default value.
19The Property - Name
- The name property establishes a means for the
program to refer to that control - By default, Control objects are assigned
relatively meaningless names when created - Programmers usually change these names to
something more meaningful
20Examples of Names
- The label controls use the default names
(Label1, etc.) - Text boxes, buttons, and the Gross Pay label
play an active role in the program and have
been changed
txtHoursWorked
Label1
txtPayRate
Label2
lblGrossPay
Label3
btnCalcGrossPay
btnClose
21Naming Conventions
- Control names must start with a letter
- Remaining characters may be letters, digits, or
underscore - 1st 3 lowercase letters indicate the type of
control - txt for Text Boxes
- lbl for Labels
- btn for Buttons
- After that, capitalize the first letter of each
word - txtHoursWorked is clearer than txthoursworked
22Moving OnVB Language Elements
- Programmer-defined-names Names created by the
programmer (e.g., lblGrossPay, btnClose) - Keywords Words with special meaning to Visual
Basic (e.g., Private, Sub) - Operators Special symbols to perform common
operations (e.g., , -, , and /) - Remarks Comments inserted by the programmer
these are ignored when the program runs (e.g.,
any text preceded by a single quote)
23Time out for Definition Syntax
- Syntax defines the correct use of key words,
operators, programmer-defined names - Similar to the syntax (rules) of English that
defines correct use of nouns, verbs, etc. - A program that violates the rules of syntax will
not run until corrected