nigelandrewfoster
Well-known Member
- Joined
- May 27, 2009
- Messages
- 747
Hello there. Most puzzling.
The following worked first time I tried it, now it fails on the highlighted line with
Object does not support this property or method
Simple test Hotel class:
Hotels collection class:
The class was exported
It was then deleted
Attribute line of code was added within Notepad
The class module was reimported
When I first ran the code it worked. Subsequently, it has failed as though the Attribute line had never been added...?
Test sub:
I have made great strides over the last few weeks in writing and using classes. It is a little frustrating to not have the liberty to use For Each in my own collection classes. Why would it work once only? That's the mystery.
Thanks for your time, it is much appreciated.
Nigel Foster
The following worked first time I tried it, now it fails on the highlighted line with
Object does not support this property or method
Simple test Hotel class:
Code:
Option Explicit
Private pName As String
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(Value As String)
pName = Value
End Property
Hotels collection class:
Code:
Option Explicit
Private pHotels As Collection
Private Sub Class_Initialize()
Set pHotels = New Collection
End Sub
Public Sub Add(Item As Hotel, Key As String)
pHotels.Add Item, Key
End Sub
Public Function NewEnum() As IUnknown
Set NewEnum = Hotels.[_NewEnum]
Attribute NewEnum.VB.UserMemID = - 4
End Function
The class was exported
It was then deleted
Attribute line of code was added within Notepad
The class module was reimported
When I first ran the code it worked. Subsequently, it has failed as though the Attribute line had never been added...?
Test sub:
Code:
Option Explicit
Public oHotels As Hotels
Sub Initialise()
Dim oHotel As Hotel
Dim r As Range
Set oHotels = New Hotels
For Each r In [a1:a8]
Set oHotel = New Hotel
oHotel.Name = r.Value
oHotels.Add oHotel, oHotel.Name
Next
[I][B]For Each oHotel In oHotels[/B][/I]
Debug.Print oHotel.Name
Next
End Sub
I have made great strides over the last few weeks in writing and using classes. It is a little frustrating to not have the liberty to use For Each in my own collection classes. Why would it work once only? That's the mystery.
Thanks for your time, it is much appreciated.
Nigel Foster
Last edited: