dblock247
01-27-2011, 08:29 AM
Im new here im have coded before but this is my first time with vba. What i am trying to accomplish is this. I want two custom objects and collections classes. The first being tickets the second employees. Needsless to say i will be tracking the tickets and the employees who write them as well as all sorts of states that are accumulated from the tickets writting.
To record the ticket its just a simple spreadsheet with ticket number the employee who wrote it, price ect. Now what i want to have is an employee object and a ticket object. They both will be put into collections (employee collection and tickets collection). I am having trouble getting every thing to work properly can you look at my code and explain to be what im doin wrong.
Custome employee class properties:
Public empID As String
Public empName As String
Public empRate As Double
Public empIRate As Double
Public empRoll As Integer
Public empDW As Double
Public empPAI As Double
Public empSLP As Double
Public empTickets As Integer
Cutome ticket properties:
Public tktNumber
Public tktType
Public tktSource
Public tktRate
Public tktDW
Public tktPAI
Public tktSLP
Public tktSU
Public tktGAS
Public tktRAP
Public tktGPS
Public tktCORP
Public tktEID
Custome Employee collection class:
Option Explicit
Private AllEmployees As New Collection
Public Sub Add(recEmployee As clsEmployee)
AllEmployees.Add recEmployee, recEmployee.empID
End Sub
Public Property Get Count() As Long
Count = AllEmployees.Count
End Property
Public Property Get Items() As Collection
Set Items = AllEmployees
End Property
Public Sub Remove(myItem As Variant)
AllEmployees.Remove (myItem)
End Sub
Custom ticket collection class:
Option Explicit
Private AllTickets As New Collection
Public Sub Add(recTicket As clsTicket)
AllTickets.Add recTicket, recTicket.tktNumber
End Sub
Public Property Get Count() As Long
Count = AllTickets.Count
End Property
Public Property Get Items() As Collection
Set Items = AllTickets
End Property
Public Sub Remove(myItem As Variant)
AllTickets.Remove (myItem)
End Sub
Tracker class used to manipulate other custom objects
Sub tktAddCollection()
Dim colTickets As New clsTickets
Dim recTicket As New clsTicket
Dim LastRow As Integer, myCount As Integer
Dim tktArray As Variant
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
tktArray = ActiveSheet.Range(Cells(3, 1), Cells(LastRow, 4))
For myCount = 1 To UBound(tktArray)
Set recTicket = New clsTicket
With recTicket
.tktNumber = tktArray(myCount, 1)
.tktType = tktArray(myCount, 2)
.tktSource = tktArray(myCount, 3)
.tktRate = tktArray(myCount, 4)
colTickets.Add recTicket
MsgBox "Ticket num: " & .tktNumber
End With
Next myCount
MsgBox "Total Number of tickets is" & colTickets.Count
Set recTicket = Nothing
End Sub
Sub EmpAddCollection()
Dim colEmployees As New clsEmployees
Dim recEmployee As New clsEmployee
Dim LastRow As Integer, myCount As Integer
Dim empArray As Variant
Dim employees As Worksheet, empInfo As Range
Set employees = ThisWorkbook.Worksheets("Employees")
Set empInfo = employees.Range("A2:B20")
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
empArray = ActiveSheet.Range(Cells(3, 1), Cells(LastRow, 4))
For myCount = 1 To UBound(empArray)
Set recEmployee = New clsEmployee
With recEmployee
.empID = empArray(myCount, 1)
.empName = empArray(myCount, 2)
colEmployees.Add recEmployee
MsgBox "Employee num: " & .empID
End With
Next myCount
MsgBox "Total Number of tickets is" & colTickets.Count
Set recTicket = Nothing
End Sub
I would be very grateful for some help please!!!
To record the ticket its just a simple spreadsheet with ticket number the employee who wrote it, price ect. Now what i want to have is an employee object and a ticket object. They both will be put into collections (employee collection and tickets collection). I am having trouble getting every thing to work properly can you look at my code and explain to be what im doin wrong.
Custome employee class properties:
Public empID As String
Public empName As String
Public empRate As Double
Public empIRate As Double
Public empRoll As Integer
Public empDW As Double
Public empPAI As Double
Public empSLP As Double
Public empTickets As Integer
Cutome ticket properties:
Public tktNumber
Public tktType
Public tktSource
Public tktRate
Public tktDW
Public tktPAI
Public tktSLP
Public tktSU
Public tktGAS
Public tktRAP
Public tktGPS
Public tktCORP
Public tktEID
Custome Employee collection class:
Option Explicit
Private AllEmployees As New Collection
Public Sub Add(recEmployee As clsEmployee)
AllEmployees.Add recEmployee, recEmployee.empID
End Sub
Public Property Get Count() As Long
Count = AllEmployees.Count
End Property
Public Property Get Items() As Collection
Set Items = AllEmployees
End Property
Public Sub Remove(myItem As Variant)
AllEmployees.Remove (myItem)
End Sub
Custom ticket collection class:
Option Explicit
Private AllTickets As New Collection
Public Sub Add(recTicket As clsTicket)
AllTickets.Add recTicket, recTicket.tktNumber
End Sub
Public Property Get Count() As Long
Count = AllTickets.Count
End Property
Public Property Get Items() As Collection
Set Items = AllTickets
End Property
Public Sub Remove(myItem As Variant)
AllTickets.Remove (myItem)
End Sub
Tracker class used to manipulate other custom objects
Sub tktAddCollection()
Dim colTickets As New clsTickets
Dim recTicket As New clsTicket
Dim LastRow As Integer, myCount As Integer
Dim tktArray As Variant
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
tktArray = ActiveSheet.Range(Cells(3, 1), Cells(LastRow, 4))
For myCount = 1 To UBound(tktArray)
Set recTicket = New clsTicket
With recTicket
.tktNumber = tktArray(myCount, 1)
.tktType = tktArray(myCount, 2)
.tktSource = tktArray(myCount, 3)
.tktRate = tktArray(myCount, 4)
colTickets.Add recTicket
MsgBox "Ticket num: " & .tktNumber
End With
Next myCount
MsgBox "Total Number of tickets is" & colTickets.Count
Set recTicket = Nothing
End Sub
Sub EmpAddCollection()
Dim colEmployees As New clsEmployees
Dim recEmployee As New clsEmployee
Dim LastRow As Integer, myCount As Integer
Dim empArray As Variant
Dim employees As Worksheet, empInfo As Range
Set employees = ThisWorkbook.Worksheets("Employees")
Set empInfo = employees.Range("A2:B20")
LastRow = ActiveSheet.Cells(ActiveSheet.Rows.Count, 1).End(xlUp).Row
empArray = ActiveSheet.Range(Cells(3, 1), Cells(LastRow, 4))
For myCount = 1 To UBound(empArray)
Set recEmployee = New clsEmployee
With recEmployee
.empID = empArray(myCount, 1)
.empName = empArray(myCount, 2)
colEmployees.Add recEmployee
MsgBox "Employee num: " & .empID
End With
Next myCount
MsgBox "Total Number of tickets is" & colTickets.Count
Set recTicket = Nothing
End Sub
I would be very grateful for some help please!!!