Share custom collection between classes using vb.net

Good morning. Well as you all know it is election day. Thank God its almost over is all I can say. On the bright side I go to get my passport picture taken for our trip to the Dominican Republic today. So glad that is over too.

Our topic today is sharing a custom collection between classes. Now remember because it is shared you have to, if using in a form for example say:

Form1._testParams.Add(…)

Make it a great day!

Imports System
Imports System.Collections
Imports System.Collections.CollectionBase
Namespace Test
    Public Class TestParams
        Inherits System.Collections.CollectionBase
        Private Sub New()
 
        End Sub
 
        Public Overloads Function Add(ByVal value As TestParam) As TestParam
            Me.List.Add(value)
            Return value
        End Function
 
        Public Overloads Sub Remove(ByVal value As TestParam)
            Me.List.Remove(value)
        End Sub
 
        Public ReadOnly Property Item(ByVal index As Integer) As TestParam
            Get
             
                Return CType(Me.List.Item(index), TestParam)
            End Get
        End Property
 
    End Class
End Namespace
 
Namespace Test
    Public Class TestParam
        Private _sn As String
        Private _pn As String
        Private _slot As Integer
        Private _ipaddr As String
        Private _testPass As Boolean
        Private _stepPass As Boolean
        Private _salesOrder As String
        Private _error As String
 
#Region "TestParam Properties"
        Public Property SN() As String
            Get
                Return _sn
            End Get
            Set(ByVal value As String)
                _sn = value
            End Set
        End Property
 
        Public Property PN() As String
            Get
                Return _pn
            End Get
            Set(ByVal value As String)
                _pn = value
            End Set
        End Property
 
        Public Property SLOT() As Integer
            Get
                Return _slot
            End Get
            Set(ByVal value As Integer)
                _slot = value
            End Set
        End Property
        Public Property IPADDR() As String
            Get
                Return _ipaddr
            End Get
            Set(ByVal value As String)
                _ipaddr = value
            End Set
        End Property
 
        Public Property TESTPASS() As Boolean
            Get
                Return _testPass
            End Get
            Set(ByVal value As Boolean)
                _testPass = value
            End Set
        End Property
 
        Public Property STEPPASS() As Boolean
            Get
                Return _stepPass
            End Get
            Set(ByVal value As Boolean)
                _stepPass = value
            End Set
        End Property
 
        Public Property SALESORDER() As String
            Get
                Return _salesOrder
            End Get
            Set(ByVal value As String)
                _salesOrder = value
            End Set
        End Property
 
        Public Property ERR() As String
            Get
                Return _error
            End Get
            Set(ByVal value As String)
                _error = value
            End Set
        End Property
#End Region
 
    End Class
End Namespace
 
' the collection is declared in the form'
Public Shared _testParams As Test.TestParams
 
Advertisements
  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: