0 index
1 Properties
2 Properties Characteristics
3 Properties are used to:
4 Properties can be changed at:
5 Properties can be changed at:
6 Example:
7 Methods
8 Method Characteristics
9 Examples
10 Common Methods
11 Events
12 Event Driven Program Design
13 Example:
14 Common Events
15 Getting Help
16 Help Menu in VB
17 Keyword Help
18 General Declarations
19 Some New Objects
20 Timer Properties
21 Timer Events
22 New Properties
23 New Functions
24 Sample Syntax
25 Time
26 Sample Syntax:
27 End
28 Syntax Examples

outline
created using slideshow.cgi by Andy Harris















CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
1. Properties
  • Properties are a number of variables associated with an object
  • Each object has a different list of properties
  • Some properties are common to most objects (visible)
  • Some properties are specific to only one type of object (Max, Min in scroll bars)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
2. Properties Characteristics
  • Can have different types of values:
    - Text (caption)
    - Numeric (min, max)
    - Boolean - True/False (visible)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
3. Properties are used to:
  • Refine an object's appearance (BackColor)
  • Refine an object's behavior (Enabled)
  • Set up the object so it will do what the programmer wants (Design time)
  • Change the characteristics of the property while the program is running (Run time)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
4. Properties can be changed at:
  • Design time:
    - as the program is being built
    - uses the properties box
    - All properties will be set this way when the program starts execution



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
5. Properties can be changed at:
  • Run time:
    - while the program is running
    - is accomplished using code
    - allows properties to be changed on the fly
    - allows response to environmental (user) input



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
6. Example:
  • MyFirst used
    - design time to set up the BackColor of the picture boxes
    - run time to set up the BackColor of the form



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
7. Methods
  • A special kind of command attached to specific objects
  • Works only with the object it is attached to
  • Some objects (check boxes) have a few methods
  • Others (data controls) have many



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
8. Method Characteristics
  • Usually found searching the online help
  • Activated only in run time
  • Relatively limited use
  • Syntax: Object.Method



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
9. Examples
  • Move event - used to move an object
  • Syntax - Object.Move X, Y, Height, Width
    - where X and Y are coordinates the object will be moved to
    - height and width are the size of the object



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
10. Common Methods
  • Hide, Show used with forms
  • AddItem used with listboxes, grids
  • Print, EndDoc to print to printer



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
11. Events
  • Are the stimuli an object can recognize
  • Are listed in the Proc box of the object's code window
  • Some events are nearly universal (e.g., Click)
  • Can be activated by the user (e.g., Click)
  • Some are object specific (e.g., Timer)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
12. Event Driven Program Design
  • Most code in Visual Basic is related to an object-event relationship
  • The user or environment activates events in objects, which then activates code
  • Very different than earlier types of program organization techniques



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
13. Example:
  • Picture1_Click in last week's program
  • Read 'When the user CLICKS on the PICTURE1 control, this will happen.'



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
14. Common Events
  • Click, Double-click
  • Load, Unload on forms
  • Change on controls that get user input
  • Paint on controls that contain graphical information



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
15. Getting Help
  • Visual Basic is a complex, growing language with many subtleties
  • Traditional reference books are cumbersome
  • There is a hypertext online help which uses a Windows help engine



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
16. Help Menu in VB
  • Contents and submenu is good if you need general information
  • Search for Help on - is much more flexible
    - type in whatever you want help on
    - a list of similar topics will appear
    - select the topic you want



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
17. Keyword Help
  • This is the fastest way to get help
  • Type or point to a keyword that you are having trouble with in a code window
  • Be sure the cursor is somewhere inside that word
  • Hit the F1 key
    - if the word is a keyword and spelled correctly,
    a help screen for that word will appear
    - good for checking syntax



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
18. General Declarations
  • This is an area that can be used to make comments about your program
  • Example:
    'Create a clock that displays a time in a label.
    'Place two horizontal scroll bars on the form,
    'one that will change the backcolor of the clock label and one
    'that will change the forecolor of the clock label.



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
19. Some New Objects
  • Timer
    - is invisible at run time
    - goes 'off' at specified intervals
    - used to replace loops



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
20. Timer Properties
  • Interval (in 1000ths of a second)
  • Enabled (True or False)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
21. Timer Events
  • Timer
    - it has 'gone off'



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
22. New Properties
  • BackColor, ForeColor - attached to most objects
  • FontName - tells which font to use in current object
  • FontSize - tells the size of the current font



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
23. New Functions
  • QBColor
    - gets a color using the Qbasic value
    - uses a number between 0 and 15
    - is an easy way to get most common colors



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
24. Sample Syntax
  • frmSample.BackColor = QBColor (4)



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
25. Time
  • Time (displays 12 hour clock)
  • Time$ (displays 24 hour clock)
  • Gets the current time from the system clock and returns it as a string



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
26. Sample Syntax:
  • lblTime.Caption = Time
    or
    lblTime.Caption = Time$



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
27. End
  • Ends the program



































CSCI N331 Visual Basic: n331/vb03PropertiesEventsMethods
28. Syntax Examples
  • Private Sub Timer1_Timer()
       'when the form loads the clock
       'should appear in the lblClockFace
       'caption area
       lblClockFace.Caption = Time
    End Sub



































outline

Properties

Properties Characteristics

Properties are used to:

Properties can be changed at:

Properties can be changed at:

Example:

Methods

Method Characteristics

Examples

Common Methods

Events

Event Driven Program Design

Example:

Common Events

Getting Help

Help Menu in VB

Keyword Help

General Declarations

Some New Objects

Timer Properties

Timer Events

New Properties

New Functions

Sample Syntax

Time

Sample Syntax:

End

Syntax Examples