Lesson 1
(Chapter 3)

Why use Visual Basic?

bullet macro language for Microsoft Applications
bullet widely used
bullet object oriented programming

What is Object Oriented Programming (OOP)?

Objects

bullet characteristics (properties)
bullet function
bullet events

Visual Basic

bullet objects
bullet forms
bullet controls
bullet characteristics (properties)
bullet the property box
bullet function
bullet methods
bullet code

Events (sending messages)

bullet mouse click
bullet key press
bullet other

Steps in designing a program

bullet Design the interface (visually)
bullet Set the properties- Name ALL objects using standard prefixes
bullet Write the Code

Object Naming Conventions

Object Type

prefix Example
Form frm frmHello
Text Box txt txtHello
Label lbl lblHello
Command Button cmd cmdExit

Event driven programming

Naming conventions

form frmSomething
text box txtSomething
command button cmdSomething
label lblSomething

Programming in Visual Basic

A Three step process:

bullet Design the interface
bullet Set the Properties
bullet Write the Code

Many Ways to say "Hello"

Printing on the form

    Start Visual Basic 6.0  
    Design the interface This is already done in this case- the only object we will use is the form itself.
    Set the properties name= frmHello
    caption = Hello
    BackColor= make it blue
    FontColor= make it white
    Font= pick a nice, big one!
    Write the code Double-click on the form
    Select Activate from the Events Window

    Type the code
    Print "Hello"

    When the form is activated (the program is run) the Activate event has occurred, so the code is executed.

Using a message box and button

Design The Interface We only need the form and a button
Set the Properties Use the same properties as above for form.

For the Button:

name=cmdHello

caption=Hello

Write the Code Double-click on the button

Enter the following code:

MsgBox("Hello, World")

Using a label

Design the form

Set the properties
Form name = frmHello
BackColor = Blue
Caption = Hello World
Command Button name = cmdHello
caption= Hello
Command Button name=cmdClear
caption=Clear
Command Button name=cmdExit
caption=Exit
Label name=lblHello
caption=lblHello
pick a nice font and colors
Write the Code cmdHello
cmdClear
cmdExit
lblHello.Text = "Hello, World!"
lblHello.Text = ""
end

Homework

Complete exercises 1 - 13 in chapter 3 (beginning on page 3-23).