Upload
kelly-tillson
View
227
Download
3
Tags:
Embed Size (px)
Citation preview
VISUAL BASIC
• Visual Basic is derived from the Basic language (Beginner’s All-Purpose Symbolic Instruction Code)
• Visual Basic uses an event-driven programming model.
PROCEDURAL V. EVENT-DRIVEN PROGRAMMING• Procedural Applications• Application execution starts with the first line of code, and
follows a predefined path through the application
• Event-Driven Applications
• Runs different code sections in response to events. Events can be triggered by the user's actions.
• The sequence of events determines the sequence in which the code runs.
• Therefore, the path through the application's code differs each time the program runs.
VISUAL BASIC EXAMPLE
VISUAL BASIC WINDOWMenu Bar
Tool Bar
Tool Box
Project Explorer Window
Properties Window
Form Layout Window
STEPS TO CREATE AN APPLICATION IN VISUAL
BASIC
1. Create the user interface of the application.
2. Write code that responds to actions taken in the user interface.
DEMONSTRATION
ADDING A LABEL OBJECT
• Is used to display information
• Label Properties:
Name: - identifies an object
- begin object name with lbl
Caption: - changes the text displayed in the label
Font: - changes the font, style and size
Alignment: - can be set to left, right or center
LABEL
ADDING A COMMAND BUTTON
• Is something the user can click on
• Label Properties:
Name: - begin object
name with cmd
Caption: - changes the text displayed in the command
button
Command Button
FORM PROPERTIES
• An object used to hold other objects
• Name – begin form objects with frm
• Caption – changes the text displayed in the title bar
EXERCISE
• GO TO PAGE 3-6
• WORK ON REVIEW NO. 2
PROGRAM CODE
• Is a set of instructions that tells the computer how to perform a specific task
EVENT PROCEDURE
• Is a block of code that executes in response to an event (ex. a mouse click)
• Ex. Done Command Button
– Unload form name or Unload Me
EXERCISE
• GO TO PAGE 3-10
• WORK ON REVIEW 3 AND 4
USING ASSIGNMENT TO CHANGE PROPERTY VALUES
• LABEL PROPERTIESCaption can be assigned textFont – can change the size
Bold and Italic are either True or Falsecan change the font name
Alignment can be assigned 0 (left justify), 1 (right justify), or 2 (center)
• COMMAND BUTTONSCaption can be assigned text
• FORM PROPERTIESCaption can be assigned text
EXAMPLEPrivate Sub CMDDONE_Click()
Unload FRMNAME
End Sub
Private Sub CMDGORDON_Click()
LBLNAME.Caption = "MY NAME IS GORDON"
End Sub
Private Sub CMDJOHN_Click()
LBLNAME.Caption = "MY NAME IS JOHN"
End Sub
Private Sub CMDMARY_Click()
LBLNAME.Caption = "MY NAME IS MARY"
End Sub
FORM LOAD EVENT PROCEDURE
• Is executed when a form is loaded into memory (when an application is started).
• Is an alternative to setting property values in the Properties window
Example
Private Sub Form_Load()
LBLNAME.CAPTION = “MY NAME IS …”
LBLNAME.ALIGNMENT = 2
End Sub
COMMENTING CODE
• Comments are used to explain and clarify program code for a human reader
• Has no effect on the way an application runs
• Single quotation mark ( ‘ ) must begin a comment
EXERCISE
• GO TO PAGE 3-13
• WORK ON REVIEW NO. 5
IMAGE OBJECTS
• Name – begin object name with img
• Picture – is used to display a dialog box for selecting the graphic
• Stretch – can be either True or False (True means the image is resized if the image box is resized)
• Visible – can be either True or False
IMAGE
EXERCISE
• GO TO PAGE 3-16
• WORK ON REVIEW 6
OPERATORS AND EXPRESSIONS
• Exponentiation (^ )• Multiplication ( *)• Division ( / )• Addition ( + )• Subtraction ( - )• BEDMAS• Example: lblAnswer.Caption = 3.14 *10 ^ 2
CREATING AN EXECUTABLE FILE
• Visual Basic includes a compiler that translates the program code into a separate executable file
• An executable file can run without Visual Basic
• Go to File and then select Make
EXERCISE
• Go to Page 3-18
• Complete Review 7 and 8
DEFINE THE FOLLOWING TERMS:
• OOP• Project• Statement• Run time• Properties window• Project explorer window• Code editor window• Design Time• Form Layout window• IDE• Interface• Tool Box• Tool Bar
Exercises
• Go to page 3-23
• Begin working on the exercises