Re: Collections Woes - Help!

Tech-Archive recommends: Fix windows errors by optimizing your registry



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
>


.



Relevant Pages

  • Re: Conversion from VB6 to VB.NET
    ... Public Function serverActiveCallback(ByVal xmlServerActive As String) As Long ... Debug.Print "Active server is " & xmlServerActive ... Public Function clusterCreatedCallback(ByVal cluster As String) As Long ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Expert help needed
    ... server end. ... > Public Function UploadFileAs Byte, ... > ByVal FlName As String) As Boolean ...
    (microsoft.public.dotnet.languages.vb)
  • Re: E-mail problem
    ... Could you verify that your smtp server is available? ... > Public Sub SendMailMultipleAttachments(ByVal From As String, ...
    (microsoft.public.dotnet.languages.vb)
  • Re: xsd:dateTime incompatibility between .Net and Apache Axis
    ... whether Java is the server and .NET is the ... > client, or vice versa. ... BTW, when I added authentication, I set PreAuthenticate to True. ... Public Sub New ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: E-mail problem
    ... set the smtpmail.smtpserver to an smtp server that you know is trouble ... > the same error whether I specify a remote mail server like ... > Public Sub SendMailMultipleAttachments(ByVal From As String, ...
    (microsoft.public.dotnet.languages.vb)