Presentation is loading. Please wait.

Presentation is loading. Please wait.

Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5

Similar presentations


Presentation on theme: "Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5"— Presentation transcript:

1 Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5

2 Objectives Understanding objects Class Modules Properties Get/Let
Defining Types Collections ‘Tirgul’ # 5

3 Object Classes Objects contains: Data Behavior Controls are objects
data (properties) behavior(Functions and events) All objects of the same type has the same data and behavior ‘Tirgul’ # 5

4 The Class Module A class is a template: it defines the data and behavior of the objects that belong to it. An instance is a variable associated with an object (a specific instance of a class). ‘Tirgul’ # 5

5 timeToCrewel(Dist as integer) as integer setSpeed(Speed as integer)
The Snail Abstraction timeToCrewel(Dist as integer) as integer age goToSleep() IsSleep setSpeed(Speed as integer) Color Gender Properties Functions ‘Tirgul’ # 5

6 All Objects has the same properties and behavior
Multiple instances of a class Class Car Color as Colur Speed as Double Size as Double Color = red Speed = 200 Size = 100.5 Color = Blue Speed = 120 Size = 160.7 Color = Yellow Speed = 90 Size = 150.6 All Objects has the same properties and behavior But not same values ‘Tirgul’ # 5

7 Property Methods Provide access to the instance variables
can assign or retrieve the value of an instance variable property A named attribute of an object. Define object characteristics such as size, color, and screen location, or the state of an object, such as enabled or disabled. ‘Tirgul’ # 5

8 Property Let Assign a value to a class property Syntax: Optionally:
Use ByVal retain the value of the parameter Dim sName as String Property Let Name(ByVal newName As String) sName = newName End Property ‘Tirgul’ # 5

9 Property Get Gets a value of a property Syntax: Dim sName as String
Property Get Name() as String Name = sName End Property ‘Tirgul’ # 5

10 Class Initialization Important for defaults
Will be called each new Instance Private Sub Class_Initialize() CTN = “ ” age = 0 fName = “” End Sub ‘Tirgul’ # 5

11 Behavior Functions Defines the behavior of the object
Done same as form functions/Subs Public will be used by the user Private will be hidden for the user Public function getSalary(code as integer) as double getSalary = getSalaryByCode(code) End function Private function getSalaryByCode(code as integer) as double getSalaryByCode = rsSalary.Field(code).value ‘Tirgul’ # 5

12 Class can use class ‘Tirgul’ # 5

13 Declaring an Object Variable
You need to define the object and create new instance. Could be done in the same line but better to separate Set: Assign an object reference to variable Dim myStudent as new cStudents Dim myStudent as cStudents Set myStudent = new cStudents ‘Tirgul’ # 5

14 Collections A very useful object to hold objects
Unlike List, can hold Objects Functions Add – Adding objects Item(index) – retrieve the Item in the index Count – Number of items Remove(Index) – remove an Item in the index Dim Emp1 as new cEmployee Dim Emp2 as new cEmployee Dim Factory As New Collection Factory.Add Emp1 Factory.Add Emp2 ‘Tirgul’ # 5

15 Item Method Retrieves a specific Item from the collection
For index = 1 To Factory.Count Debug.Print Factory.Item(index).Name Next index Property of the item ‘Tirgul’ # 5

16 Programmer defined Data Types
Type is a degenerate class In a form (private) or module(Public) Useful to hold data in a logic group Referenced as a base type (no New) Public Type Point x as Integer Y as Integer End Type Dim myPoint as Point myPoint.x = 1 myPoint.y = 2 4 3 2 1 1 2 3 4 ‘Tirgul’ # 5

17 Source Examples prjEmployee – Simple class use
prgStudent – Properties use prgRoll_Call - Class_Initialize, Container class prgOrderItem – with reserved word prgBankAccount – Class functions prgArithmeticSeries Lec3LinkList – List example ‘Tirgul’ # 5


Download ppt "Enterprise Development Using Visual Basic 6.0 Autumn 2002 Tirgul #5"

Similar presentations


Ads by Google