PC Review


Reply
Thread Tools Rate Thread

Call to a property is setting all items in collection, not one

 
 
=?Utf-8?B?SiBTdHJlZ2Vy?=
Guest
Posts: n/a
 
      5th Sep 2007
I have a class module that has a collection of another class module (MONTH)
that has a collection of a third class module (WBSID) with a property of
ACWP. It seems that in some scenarios, if I call this line in the top level
class:

Me.Month(1).WBSID("ABC123").ACWP = 50

All WBSID with the name property of "ABC123", regardless of which month they
are in, chance to 50, even though I specifically call one month. And I just
want to set the single month's value, not any other month. Below is the code
that refers to this in my classes (sorry for lack of comments, haven't gotten
around to it). Thanks for any help as this is driving me nuts.

Top Level Class:

Private pMonth As New Collection

Property Set Months(S As Collection)
Set pMonth = S
End Property
Property Get Months() As Collection
Set Months = pMonth
End Property
Public Function Month(index As Integer) As clsMonth

If index > pMonth.Count Or index < 1 Then
Err.Raise 9
Else
Set Month = pMonth(index)
End If

End Function

Month class:

Private pWBSID As New Collection

Property Set WBSIDs(S As Collection)
Set pWBSID = S
End Property
Property Get WBSIDs() As Collection
Set WBSIDs = pWBSID
End Property
Public Function WBSID(index As Variant) As clsWBSID
If IsNumeric(index) Then
If index > pWBSID.Count Or index < 1 Then
Err.Raise 9
Else
Set WBSID = pWBSID(index)
End If
Else

Dim WP As clsWBSID

For Each WP In pWBSID
If UCase(WP.ChargeCode) = UCase(index) Then
Set WBSID = WP
Exit For
End If
Next

End If
End Function

WBSID Class:

Private pACWP As Double
Private pChargeCode As String

Public Property Let ChargeCode(S As String)
pChargeCode = S
End Property
Public Property Get ChargeCode() As String
ChargeCode = pChargeCode
End Property
Public Property Let ACWP(S As Double)
pACWP = Round(S, 1)
End Property
Public Property Get ACWP() As Double
ACWP = pACWP
End Property
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003

 
Reply With Quote
 
 
 
 
Tim Williams
Guest
Posts: n/a
 
      5th Sep 2007
Have you tried explicitly specifying "Item()"

Public Function Month(index As Integer) As clsMonth

If index > pMonth.Count Or index < 1 Then
Err.Raise 9
Else
Set Month = pMonth.Item(index)
End If


End Function


I think I already made this suggestion some time ago. Did it not work ?
Item works for indexes as well as string keys.

Tim


"J Streger" <(E-Mail Removed)> wrote in message
news:4E9BFED6-23A8-44BE-BA5E-(E-Mail Removed)...
>I have a class module that has a collection of another class module (MONTH)
> that has a collection of a third class module (WBSID) with a property of
> ACWP. It seems that in some scenarios, if I call this line in the top
> level
> class:
>
> Me.Month(1).WBSID("ABC123").ACWP = 50
>
> All WBSID with the name property of "ABC123", regardless of which month
> they
> are in, chance to 50, even though I specifically call one month. And I
> just
> want to set the single month's value, not any other month. Below is the
> code
> that refers to this in my classes (sorry for lack of comments, haven't
> gotten
> around to it). Thanks for any help as this is driving me nuts.
>
> Top Level Class:
>
> Private pMonth As New Collection
>
> Property Set Months(S As Collection)
> Set pMonth = S
> End Property
> Property Get Months() As Collection
> Set Months = pMonth
> End Property
> Public Function Month(index As Integer) As clsMonth
>
> If index > pMonth.Count Or index < 1 Then
> Err.Raise 9
> Else
> Set Month = pMonth(index)
> End If
>
> End Function
>
> Month class:
>
> Private pWBSID As New Collection
>
> Property Set WBSIDs(S As Collection)
> Set pWBSID = S
> End Property
> Property Get WBSIDs() As Collection
> Set WBSIDs = pWBSID
> End Property
> Public Function WBSID(index As Variant) As clsWBSID
> If IsNumeric(index) Then
> If index > pWBSID.Count Or index < 1 Then
> Err.Raise 9
> Else
> Set WBSID = pWBSID(index)
> End If
> Else
>
> Dim WP As clsWBSID
>
> For Each WP In pWBSID
> If UCase(WP.ChargeCode) = UCase(index) Then
> Set WBSID = WP
> Exit For
> End If
> Next
>
> End If
> End Function
>
> WBSID Class:
>
> Private pACWP As Double
> Private pChargeCode As String
>
> Public Property Let ChargeCode(S As String)
> pChargeCode = S
> End Property
> Public Property Get ChargeCode() As String
> ChargeCode = pChargeCode
> End Property
> Public Property Let ACWP(S As Double)
> pACWP = Round(S, 1)
> End Property
> Public Property Get ACWP() As Double
> ACWP = pACWP
> End Property
> --
> *********************
> J Streger
> MS Office Master 2000 ed.
> MS Project White Belt 2003
>
> User of MS Office 2003
>



 
Reply With Quote
 
=?Utf-8?B?SiBTdHJlZ2Vy?=
Guest
Posts: n/a
 
      5th Sep 2007
I just tried it and no change. I was always under the impression that:

myCollection.item(index) is equivalent to myCollection(index)

Also I cannot use .item for the call to the WBSID as the value I will index
is a property of the class. I guess I can try and put the value as the key
rather than the property, but that would be a bit of work.
--
*********************
J Streger
MS Office Master 2000 ed.
MS Project White Belt 2003

User of MS Office 2003



"Tim Williams" wrote:

> Have you tried explicitly specifying "Item()"
>
> Public Function Month(index As Integer) As clsMonth
>
> If index > pMonth.Count Or index < 1 Then
> Err.Raise 9
> Else
> Set Month = pMonth.Item(index)
> End If
>
>
> End Function
>
>
> I think I already made this suggestion some time ago. Did it not work ?
> Item works for indexes as well as string keys.
>
> Tim
>
>
> "J Streger" <(E-Mail Removed)> wrote in message
> news:4E9BFED6-23A8-44BE-BA5E-(E-Mail Removed)...
> >I have a class module that has a collection of another class module (MONTH)
> > that has a collection of a third class module (WBSID) with a property of
> > ACWP. It seems that in some scenarios, if I call this line in the top
> > level
> > class:
> >
> > Me.Month(1).WBSID("ABC123").ACWP = 50
> >
> > All WBSID with the name property of "ABC123", regardless of which month
> > they
> > are in, chance to 50, even though I specifically call one month. And I
> > just
> > want to set the single month's value, not any other month. Below is the
> > code
> > that refers to this in my classes (sorry for lack of comments, haven't
> > gotten
> > around to it). Thanks for any help as this is driving me nuts.
> >
> > Top Level Class:
> >
> > Private pMonth As New Collection
> >
> > Property Set Months(S As Collection)
> > Set pMonth = S
> > End Property
> > Property Get Months() As Collection
> > Set Months = pMonth
> > End Property
> > Public Function Month(index As Integer) As clsMonth
> >
> > If index > pMonth.Count Or index < 1 Then
> > Err.Raise 9
> > Else
> > Set Month = pMonth(index)
> > End If
> >
> > End Function
> >
> > Month class:
> >
> > Private pWBSID As New Collection
> >
> > Property Set WBSIDs(S As Collection)
> > Set pWBSID = S
> > End Property
> > Property Get WBSIDs() As Collection
> > Set WBSIDs = pWBSID
> > End Property
> > Public Function WBSID(index As Variant) As clsWBSID
> > If IsNumeric(index) Then
> > If index > pWBSID.Count Or index < 1 Then
> > Err.Raise 9
> > Else
> > Set WBSID = pWBSID(index)
> > End If
> > Else
> >
> > Dim WP As clsWBSID
> >
> > For Each WP In pWBSID
> > If UCase(WP.ChargeCode) = UCase(index) Then
> > Set WBSID = WP
> > Exit For
> > End If
> > Next
> >
> > End If
> > End Function
> >
> > WBSID Class:
> >
> > Private pACWP As Double
> > Private pChargeCode As String
> >
> > Public Property Let ChargeCode(S As String)
> > pChargeCode = S
> > End Property
> > Public Property Get ChargeCode() As String
> > ChargeCode = pChargeCode
> > End Property
> > Public Property Let ACWP(S As Double)
> > pACWP = Round(S, 1)
> > End Property
> > Public Property Get ACWP() As Double
> > ACWP = pACWP
> > End Property
> > --
> > *********************
> > J Streger
> > MS Office Master 2000 ed.
> > MS Project White Belt 2003
> >
> > User of MS Office 2003
> >

>
>
>

 
Reply With Quote
 
Tim Williams
Guest
Posts: n/a
 
      6th Sep 2007
You mention that this occurs "in some scenarios": can you reproduce these
cases reliably?
I could take a look if you can put a sample workbook together.

Tim
tim j williams
at gmail dot com
(no spaces, and the obvious stuff)






"J Streger" <(E-Mail Removed)> wrote in message
news:125C36CD-AF62-471D-9618-(E-Mail Removed)...
>I just tried it and no change. I was always under the impression that:
>
> myCollection.item(index) is equivalent to myCollection(index)
>
> Also I cannot use .item for the call to the WBSID as the value I will
> index
> is a property of the class. I guess I can try and put the value as the key
> rather than the property, but that would be a bit of work.
> --
> *********************
> J Streger
> MS Office Master 2000 ed.
> MS Project White Belt 2003
>
> User of MS Office 2003
>
>
>
> "Tim Williams" wrote:
>
>> Have you tried explicitly specifying "Item()"
>>
>> Public Function Month(index As Integer) As clsMonth
>>
>> If index > pMonth.Count Or index < 1 Then
>> Err.Raise 9
>> Else
>> Set Month = pMonth.Item(index)
>> End If
>>
>>
>> End Function
>>
>>
>> I think I already made this suggestion some time ago. Did it not work ?
>> Item works for indexes as well as string keys.
>>
>> Tim
>>
>>
>> "J Streger" <(E-Mail Removed)> wrote in message
>> news:4E9BFED6-23A8-44BE-BA5E-(E-Mail Removed)...
>> >I have a class module that has a collection of another class module
>> >(MONTH)
>> > that has a collection of a third class module (WBSID) with a property
>> > of
>> > ACWP. It seems that in some scenarios, if I call this line in the top
>> > level
>> > class:
>> >
>> > Me.Month(1).WBSID("ABC123").ACWP = 50
>> >
>> > All WBSID with the name property of "ABC123", regardless of which month
>> > they
>> > are in, chance to 50, even though I specifically call one month. And I
>> > just
>> > want to set the single month's value, not any other month. Below is the
>> > code
>> > that refers to this in my classes (sorry for lack of comments, haven't
>> > gotten
>> > around to it). Thanks for any help as this is driving me nuts.
>> >
>> > Top Level Class:
>> >
>> > Private pMonth As New Collection
>> >
>> > Property Set Months(S As Collection)
>> > Set pMonth = S
>> > End Property
>> > Property Get Months() As Collection
>> > Set Months = pMonth
>> > End Property
>> > Public Function Month(index As Integer) As clsMonth
>> >
>> > If index > pMonth.Count Or index < 1 Then
>> > Err.Raise 9
>> > Else
>> > Set Month = pMonth(index)
>> > End If
>> >
>> > End Function
>> >
>> > Month class:
>> >
>> > Private pWBSID As New Collection
>> >
>> > Property Set WBSIDs(S As Collection)
>> > Set pWBSID = S
>> > End Property
>> > Property Get WBSIDs() As Collection
>> > Set WBSIDs = pWBSID
>> > End Property
>> > Public Function WBSID(index As Variant) As clsWBSID
>> > If IsNumeric(index) Then
>> > If index > pWBSID.Count Or index < 1 Then
>> > Err.Raise 9
>> > Else
>> > Set WBSID = pWBSID(index)
>> > End If
>> > Else
>> >
>> > Dim WP As clsWBSID
>> >
>> > For Each WP In pWBSID
>> > If UCase(WP.ChargeCode) = UCase(index) Then
>> > Set WBSID = WP
>> > Exit For
>> > End If
>> > Next
>> >
>> > End If
>> > End Function
>> >
>> > WBSID Class:
>> >
>> > Private pACWP As Double
>> > Private pChargeCode As String
>> >
>> > Public Property Let ChargeCode(S As String)
>> > pChargeCode = S
>> > End Property
>> > Public Property Get ChargeCode() As String
>> > ChargeCode = pChargeCode
>> > End Property
>> > Public Property Let ACWP(S As Double)
>> > pACWP = Round(S, 1)
>> > End Property
>> > Public Property Get ACWP() As Double
>> > ACWP = pACWP
>> > End Property
>> > --
>> > *********************
>> > J Streger
>> > MS Office Master 2000 ed.
>> > MS Project White Belt 2003
>> >
>> > User of MS Office 2003
>> >

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help setting property items to a gif file Alexey Titov Microsoft Dot NET Framework 1 25th Feb 2009 09:02 AM
Designer -> 'Collection' type property -> refresh control after adding new items 12jumper@wp.pl Microsoft C# .NET 1 10th Jan 2007 03:33 PM
Adding items in collection property during design mode Saimeera Microsoft ASP .NET 0 10th May 2006 12:34 PM
Setting combo box items property? David Veeneman Microsoft Dot NET Framework Forms 1 6th Apr 2006 01:13 AM
Can't get collection to save when using collection of custom class as property of control in VS 2005 J.Edwards Microsoft Dot NET Compact Framework 0 10th Jan 2006 04:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:07 PM.