Object Oriented – OO – Visual Basic 6 Specifics – VB6
11-Aug-0909 Leave a comment
The word "Set" is often required. Omitting this in the following would compile but go through the Get routine instead and error in runtime.
Private Sub Class_Initialize()
Set Me.Employee = New Employee
End Sub
End Sub
In loops there are two options
Either Dim object as New instance inside loop. Then set to Nothing before next loop.
Do Until rsTD.EOF
Dim cTimeSheet As New clsTimeSheet
cTimeSheet.Employee.EmpeeNo = rsTD!EmpeeNo
Call cJS.colTimeSheets.AddTimeSheet(cTimeSheet, lngMaxEmp)
Set cTimeSheet = Nothing
rsTD.MoveNext
Loop
Or following with or without first New
Dim cTimeSheet As New clsTimeSheet
Do Until rsTD.EOF
Set cTimeSheet = New clsTimeSheet
cTimeSheet.Employee.EmpeeNo = rsTD!EmpeeNo
Call cJS.colTimeSheets.AddTimeSheet(cTimeSheet, lngMaxEmp)
rsTD.MoveNext
Loop