lucrahouse
MIS
I was trying to learn something new. I wanted to take an example from my book, "Teach Yourself Excel in 21 Days", on page 457, was an example of a user defined class called electric heater. I want to be able to create multiple heaters and name each one something different. Here is an example of my code so far that I have written on the class module page:
Example below is from class module called: ElectricHeater
Option Explicit
Const ehTitle = "Electric Heater"
Dim ehName As String
Property Let Name(y As String)
ehName = y
End Property
Property Get Name() As String
Name = ehName
End Property
and here is an example of code which I'm using to try to create more than one heate and see if I'm successful. But I failed.
Example below is from class module called: Module1
Sub N_heater()
Dim x As Integer
Dim objHeater As ElectricHeater
Set objHeater = New ElectricHeater
objHeater.Name = "ABC"
Set objHeater = New ElectricHeater
objHeater.Name = "DEF"
For x = 1 To 2
MsgBox "Heater name is " & objHeater.Name
Next x
End Sub
I thought I could create a collection of heaters and call them back by name. If I can call them back by name, then maybe I can call back the other variables which I want to assign to them later. Can you help me with this idea. Any instructions would be appreciated.
Example below is from class module called: ElectricHeater
Option Explicit
Const ehTitle = "Electric Heater"
Dim ehName As String
Property Let Name(y As String)
ehName = y
End Property
Property Get Name() As String
Name = ehName
End Property
and here is an example of code which I'm using to try to create more than one heate and see if I'm successful. But I failed.
Example below is from class module called: Module1
Sub N_heater()
Dim x As Integer
Dim objHeater As ElectricHeater
Set objHeater = New ElectricHeater
objHeater.Name = "ABC"
Set objHeater = New ElectricHeater
objHeater.Name = "DEF"
For x = 1 To 2
MsgBox "Heater name is " & objHeater.Name
Next x
End Sub
I thought I could create a collection of heaters and call them back by name. If I can call them back by name, then maybe I can call back the other variables which I want to assign to them later. Can you help me with this idea. Any instructions would be appreciated.