Re: Collections Woes - Help!
- From: "Claes Bergefall" <claes.bergefall@xxxxxxxxxx>
- Date: Thu, 22 Dec 2005 10:37:06 +0100
Why do you have a variable and a property with the same name (sServer)?
You could use sServer(i).Path instead of serversCollection.Item(i).Path
since you have that property but it looks really weird.
My suggestion is that you define a strongly typed ServerCollection class and
use that instead. Makes your code much easier to read and maintain:
Public Class ServerCollection
Inherits System.Collections.CollectionBase
Public Sub New()
MyBase.New()
End Sub
Default Public Property Item(ByVal index As Integer) As Server
Get
Return CType(List.Item(index), Server)
End Get
Set(ByVal value As Server)
List.Item(index) = value
End Set
End Property
Public Function Add(ByVal value As Server) As Integer
Return List.Add(value)
End Function
Public Sub AddRange(ByVal values() As Server)
For Each value As Server In values
Add(value)
Next
End Sub
Public Function Contains(ByVal value As Server) As Boolean
Return List.Contains(value)
End Function
Public Function IndexOf(ByVal value As Server) As Integer
Return List.IndexOf(value)
End Function
Public Sub Insert(ByVal index As Integer, ByVal value As Server)
List.Insert(index, value)
End Sub
Public Sub Remove(ByVal value As Server)
List.Remove(value)
End Sub
Public Sub CopyTo(ByVal values() As Server, ByVal index As Integer)
List.CopyTo(values, index)
End Sub
End Class
/claes
"Bmack500" <brett.mack@xxxxxxxxx> wrote in message
news:1135178589.445109.166280@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> I'm definitely doing something wrong here. I have a class called
> Servers, implemented as below. I then create my collection as below.
> Then, I'll add a server object to the collection as follows:
>
> Dim sServer as New Server
> sServer.Path(iIndex2) = "servername"
> serversCollection.Add(sServer)
>
> No problems. Then I try and access a variable like this:
>
> For i = 0 To (serversCollection.Count - 1)
> serversCollection.Item(i).Path = "\\servername\path\"
> Next
> I'm always getting "option strict disallows late binding" when trying
> to assign a value to one of the server objects in the collection.
>
> What am I doing wrong?
>
> '*************Create Collection************************
> Private serversCollection As New System.Collections.ArrayList
> Public Property sServer(ByVal I As Integer) As Server
> Get
> Return CType(serversCollection(I), Server)
> End Get
> Set(ByVal Value As Server)
> serversCollection(I) = Value
> End Set
> End Property
>
> '************Server Class*******************************
> Public Class Server
> Public mPath As String
> Default Public Property Path(ByVal I As Integer) As String
> Get
> Return mPath
> End Get
> Set(ByVal Value As String)
> mPath = Value
> End Set
> End Property
> 'Public InstanceName As String
> Public Name As String
> Public Nick As String
> Public Status As String
>
> Public newDat As Integer
> Public newEngine As Integer
> Public oldDat As Integer
> Public oldEngine As Integer
>
> Public datChange As Boolean
> Public engineChange As Boolean
> Public updateCycle As Boolean
> Public contactFailure As Boolean
>
> Public NumContactFailures As Integer
> Public NumUpdateCycles As Integer
>
> End Class
>
.
- References:
- Collections Woes - Help!
- From: Bmack500
- Collections Woes - Help!
- Prev by Date: Re: Decimal comma / point problem in sql
- Next by Date: Reflection and Generic
- Previous by thread: Re: Collections Woes - Help!
- Next by thread: Object Properties
- Index(es):
Relevant Pages
|