How .Items(5) + .Items.Item(5) ? 
Author Message
 How .Items(5) + .Items.Item(5) ?

How can I do the below  :-

Sub Test
    Dim Items = New myDataClass()
    Items.Item(5) = "testing
    Items(5) = "testing"
End Sub

Something like :-
    mItem = ListView1.Items(1)
    mItem = ListView1.Items.Item(0)

The below keeps giving error that "Items" conflicts even before compilation.

Public Class myDataClass

        Public Items As Collection

        Public Property Items(ByVal Index As Integer)

            Get
            End Get

            Set(ByVal Value)
            End Set

        End Property

End Class



Tue, 26 Apr 2005 16:08:26 GMT  
 How .Items(5) + .Items.Item(5) ?
    Firstly you can't have two public properties with the same name:

Quote:
>         Public Items As Collection

>         Public Property Items(ByVal Index As Integer)

    You should make "Private" the first line, and manage it from the "Items
Property"

    Second, you are looking for the "Default" keyword. Write:

        Default Public Property Items(ByVal Index As Integer)

    insteed. Remember that you can only define a "Default" property, and
this must receive at least one paremeter.

        Hope this helps,

            Luis R:C.



Quote:
> How can I do the below  :-

> Sub Test
>     Dim Items = New myDataClass()
>     Items.Item(5) = "testing
>     Items(5) = "testing"
> End Sub

> Something like :-
>     mItem = ListView1.Items(1)
>     mItem = ListView1.Items.Item(0)

> The below keeps giving error that "Items" conflicts even before
compilation.

> Public Class myDataClass

>         Public Items As Collection

>         Public Property Items(ByVal Index As Integer)

>             Get
>             End Get

>             Set(ByVal Value)
>             End Set

>         End Property

> End Class



Tue, 26 Apr 2005 17:02:53 GMT  
 How .Items(5) + .Items.Item(5) ?
Allan,
In addition to what Luis Angel stated.

A field

Quote:
>         Public Items As Collection

cannot have the same name as a property

Quote:
>         Public Property Items(ByVal Index As Integer)

I would make the field private and name is m_items. The m_ identifies it as
a member field.

Then on your Property use the Default keyword, as Luis stated, which allows
you to omit the property name.

Also, you don't show that you ever create the m_items collection. I would
add a constructor to MyDataClass that creates the collection. Also making
m_items readonly ensures that the collection itself is never replaced (the
objects within the collection can be replaced...

Public Class myDataClass

        Private ReadOnly m_items As Collection

        Public Sub New()
            m_Items = New Collection()
        End Sub

        Public Property Items(ByVal Index As Integer)
            Get
            End Get
            Set(ByVal Value)
            End Set
        End Property

End Class

Hope this helps
Jay


Quote:
> How can I do the below  :-

> Sub Test
>     Dim Items = New myDataClass()
>     Items.Item(5) = "testing
>     Items(5) = "testing"
> End Sub

> Something like :-
>     mItem = ListView1.Items(1)
>     mItem = ListView1.Items.Item(0)

> The below keeps giving error that "Items" conflicts even before
compilation.

> Public Class myDataClass

>         Public Items As Collection

>         Public Property Items(ByVal Index As Integer)

>             Get
>             End Get

>             Set(ByVal Value)
>             End Set

>         End Property

> End Class



Wed, 27 Apr 2005 13:54:06 GMT  
 How .Items(5) + .Items.Item(5) ?
Thanks alot!


Quote:
>     Firstly you can't have two public properties with the same name:

> >         Public Items As Collection

> >         Public Property Items(ByVal Index As Integer)

>     You should make "Private" the first line, and manage it from the
"Items
> Property"

>     Second, you are looking for the "Default" keyword. Write:

>         Default Public Property Items(ByVal Index As Integer)

>     insteed. Remember that you can only define a "Default" property, and
> this must receive at least one paremeter.

>         Hope this helps,

>             Luis R:C.



> > How can I do the below  :-

> > Sub Test
> >     Dim Items = New myDataClass()
> >     Items.Item(5) = "testing
> >     Items(5) = "testing"
> > End Sub

> > Something like :-
> >     mItem = ListView1.Items(1)
> >     mItem = ListView1.Items.Item(0)

> > The below keeps giving error that "Items" conflicts even before
> compilation.

> > Public Class myDataClass

> >         Public Items As Collection

> >         Public Property Items(ByVal Index As Integer)

> >             Get
> >             End Get

> >             Set(ByVal Value)
> >             End Set

> >         End Property

> > End Class



Wed, 27 Apr 2005 18:37:15 GMT  
 How .Items(5) + .Items.Item(5) ?
Thanks!!



Quote:
> Allan,
> In addition to what Luis Angel stated.

> A field
> >         Public Items As Collection

> cannot have the same name as a property
> >         Public Property Items(ByVal Index As Integer)

> I would make the field private and name is m_items. The m_ identifies it
as
> a member field.

> Then on your Property use the Default keyword, as Luis stated, which
allows
> you to omit the property name.

> Also, you don't show that you ever create the m_items collection. I would
> add a constructor to MyDataClass that creates the collection. Also making
> m_items readonly ensures that the collection itself is never replaced (the
> objects within the collection can be replaced...

> Public Class myDataClass

>         Private ReadOnly m_items As Collection

>         Public Sub New()
>             m_Items = New Collection()
>         End Sub

>         Public Property Items(ByVal Index As Integer)
>             Get
>             End Get
>             Set(ByVal Value)
>             End Set
>         End Property

> End Class

> Hope this helps
> Jay



> > How can I do the below  :-

> > Sub Test
> >     Dim Items = New myDataClass()
> >     Items.Item(5) = "testing
> >     Items(5) = "testing"
> > End Sub

> > Something like :-
> >     mItem = ListView1.Items(1)
> >     mItem = ListView1.Items.Item(0)

> > The below keeps giving error that "Items" conflicts even before
> compilation.

> > Public Class myDataClass

> >         Public Items As Collection

> >         Public Property Items(ByVal Index As Integer)

> >             Get
> >             End Get

> >             Set(ByVal Value)
> >             End Set

> >         End Property

> > End Class



Wed, 27 Apr 2005 18:37:58 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. add items and removing items from a list

2. Adding Menu item to the Mail item menu from an outlook Addin

3. ItemRemove event don't fire when removing last item in items collection object

4. Adding Menu item to the Mail item menu from an outlook Addin

5. Programmatically delete an item from the Sent items

6. Programmatically delete an item from the Sent Items Folder

7. Paste item (not contents) into body of another item

8. Howto trap MAPIFolder.Items.ItemAdd on Sent Items Folder

9. next item and previous item?

10. How to do Next item and Previous item programatically

11. How to delete selective items from Sent Items from PF Script

12. New items and Item.Size>0

 

 
Powered by phpBB® Forum Software