Visual Basic - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Visual Basic

Description:

Each property has a value ... The name property establishes a means for the program to refer to that control ... special meaning to Visual Basic (e.g., Private, ... – PowerPoint PPT presentation

Number of Views:43
Avg rating:3.0/5.0
Slides: 24
Provided by: engi96
Learn more at: https://miamioh.edu
Category:
Tags: basic | visual

less

Transcript and Presenter's Notes

Title: Visual Basic


1
Visual Basic
  • Visual Basic is an Object Oriented
    Programming language

2
Visual Basic
  • Much, Much, Much, Much less effort required
    to produce a usable program than procedural
    programming languages
  • Lets all say Hurrah

3
Visual Basic
  • As Visual Basic programmer, you will use Visual
    Studio to create
  • Objects
  • Events

4
More about Objects
  • VB uses MANY objects
  • One category of objects is referred to as
    controls
  • You are quite familiar with controls

5
Visual 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

6
Many 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

7
First 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

8
More 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

9
Event 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
10
Event 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
11
Time 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.

12
Example of a GUI
  • THIS(ignore the lines)

13
Example GUI
  • Instead of this .

Enter number of hours worked _
14
Example GUI
  • Instead of this .

Enter number of hours worked 10
15
Example GUI
  • Instead of this .

Enter number of hours worked 10 Enter hourly
pay rate _
16
Example GUI
  • Instead of this .

Enter number of hours worked 10 Enter hourly
pay rate 15
17
Example GUI
  • Instead of this .

Enter number of hours worked 10 Enter hourly
pay rate 15 Gross pay is 150.00
18
Time 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.

19
The 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

20
Examples 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
21
Naming 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

22
Moving 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)

23
Time 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
Write a Comment
User Comments (0)
About PowerShow.com