Class Object Within a Class Object

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
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
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

Forum statistics

Threads
1,215,262
Messages
6,123,939
Members
449,134
Latest member
NickWBA

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top