Lec 02
Lec 02
Daniel Chen
Topics
1. What is VB? 2. What is Event-Driven? 3. What is Object-Orientation? 4. Objects used in VB 5. VB objects naming practice 6. Files in VB 7. OOED Programming process 8. VB statements 9. VB Help
What is VB?
A windows-based system using objects responding to events An objected-oriented event-driven programming language
Event-Driven
Procedural languages run from start to finish with no human intervention
Basic, COBOL, FORTRAN, C
Event driven languages - waits for an event to occur before taking any action Example of event
The press of a key on the keyboard Movement of the mouse The click of a mouse button
Objects
Reusable software components that model items in the real world
e.g. GPA calculator, Tax calculator
They are self-contained modules that combine data and program code which pass strictly defined messages to one another
Encapsulation
The capability of an object to hide its internal workings from other objects. In VB, programmers does not need to know what is going on inside the object, but only need to know how to work with the objects properties and methods
How many drivers are mechanics?
st 1
Project (ShowName)
Finish the name with a descriptive word of the objects purpose Spaces and special characters are not allowed in an objects name. (E.g. cmdCancel) Examples might be:
frmMain.BackColor = vbRed txtState.Text = ""
Features of Objects
The programmer can manipulate the object through the use of three key object features: properties methods events
Object Properties
A property is a named attribute of an object. Using an analogy to English grammar, if an object is thought of as a noun, then a property may be thought of as an adjective. Used to change the appearance of objects.
An example of the relationship between objects and properties using an everyday object:
shirt.color = "Green shirt.launder = "Clean
Object Methods
A set of predefined activities that an object can carry out. The syntax for using an objects method is:
object.method
A method is a verb that can be carried out by the object. For the various VB objects, there are usually several methods already available. Or advanced programmers can create their own methods.
Methods Example
Real life example
dog.eat dog.bark dog.run
Object Event
An action taken by the object when notified by a message Or, user actions taken on the object that provokes a response from the object. Examples Soccer ball: kicking, throwing, holding etc. Cat: feeding, hitting, calling etc. mouse click, form load, or key press.
VB example
Private Sub cmdsubmit_Click() End Sub
Save files
Important! Save early. All three types can and should have same names. Eliminate prefix (eg.frm)
Add graphic
Retrieve your 1st project from your disk Use image control Select a graphic Change the size of graphic
Stretch property of image control
Save it
Use your last name
Eg. chen.frm, chen.vbp, chen.frx
Create a folder in your disk composed of your name Copy files to your folder Drag the folder to:
W:\apps\classes\mist4600\homework\ Dchen\testfile folder
Comments
To explain the purpose of a program, or a statement, a comment statement is added
For yourself and others
Any statement beginning with an apostrophe or REM is a comment Comments can be added to end of statements using apostrophe
VB Statements
A statement is a reserved word Statements are instructions that are built into the Visual Basic language
Some examples are: End
Option Explicit Private Sub Dim
In VB 6, Help uses the familiar Internet Explorer browser interface for the first two types of help. You can seek help by selecting Contents, Index, or Search from the Help menu item