wordizlife
New Member
- Joined
- Nov 9, 2014
- Messages
- 1
Hi Guys,
I am trying to code a class object that will contain another class object.
I am not sure how to go about doing this as I am new to working with classes.
I have created a cParts Class and a cBatch Class.
I would like to be be able to program this so I can access the data like:
Ex: PartsList(0).Part("PartName").Batch("BatchID").Value
In other words the BatchID Object needs to be within the Part object.
First Class Module
Second Class Module:
Main Module:
I am trying to code a class object that will contain another class object.
I am not sure how to go about doing this as I am new to working with classes.
I have created a cParts Class and a cBatch Class.
I would like to be be able to program this so I can access the data like:
Ex: PartsList(0).Part("PartName").Batch("BatchID").Value
In other words the BatchID Object needs to be within the Part object.
First Class Module
Code:
'Class cParts
'Attributes
'
'PrivateAttributes
Private pPartName As String
'Get Methods
'Get PartName
Public Property Get PartName() As String
PartName = pPartName
End Property
'Set Methods
'Set PartName
Public Property Let PartName(Value As String)
pPartName = Value
End Property
Second Class Module:
Code:
Dim pBatchID As String
'Get Class Name
Public Property Get BatchID() As String
BatchID = pBatchID
End Property
'Set Class Name
Public Property Let BatchID(Value As String)
pBatchID = Value
End Property
Main Module:
Code:
' Main module
Dim PartsList As Variant
Dim BatchList As Variant
Sub main()
PartsList = Array(New cParts)
BatchList = Array(New cBatch)
Set BatchList(0) = NewBatch("15V-1.04")
Set PartsList(0) = NewPart("MRJ")
'Name = "MRJ"
'Set wanted = GetPart(Name)
'Debug.Print wanted.PartName
End Sub
'Code to initialise new part
Function NewPart(Name As String)
Dim Part As cParts
Set Part = New cParts
Part.PartName = Value
Set NewPart = Part
End Function
Function NewBatch(Value As String)
Dim Batch As cBatch
Set Batch = New cBatch
Batch.BatchID = Value
Set NewBatch = Batch
End Function