How do I initialize/utilize an arraylist and a hashtable defined in a different class?


I have a routine where I need to clear 2 arrays and a hashtable, but they are defined in a different class (frmTimelineViewer).  

I tried doing a Dim aFFOrder as New... But it isn't available from the list of options when I type frmTimelineViewer.

How do I intialize/utilize these arraylists and the hashtable from another class?

Public Sub ProcessFFData(ByVal Lap As Integer, ByVal RunID As Integer)
        frmTimelineSerial.FFOrderArray.Clear() 'If I try to run this or any of the following 2 lines, I get a NullReferenceException Error. 
        Using TableAdapter As New ReportingDataTableAdapters.FFOrderTableAdapter()
            Using DataTable As ReportingData.FFOrderDataTable = TableAdapter.GetData(Lap, RunID)
                Dim Row As ReportingData.FFOrderRow
                Dim li As ListViewItem
                Dim i As Integer = 0
                For Each Row In DataTable
                    li = frmTimelineSerial.lvFF.Items.Add(Row.CarNumber)
                    frmTimelineSerial.FFOrderArray.Add(Row.CarNumber) ' The same thing happens with these two lines.
                    frmTimelineSerial.FFOrderHT.Add(Row.CarNumber, i)
            End Using
        End Using
    End Sub

Open in new window

Who is Participating?
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:

(1) Pass a reference to those objects into your sub.
(2) Make them shared so you can access them from anywhere.
(3) Place them in a Module as Public so they can be accessed from anywhere.

There are other methods depending on your situation...
indy500fanAuthor Commented:
Would you agree declaring them as the following would be wrong?  Should I declare them as New or is that a bad idea?

   Public Shared FFOrderArray As New ArrayList

    Public Shared FFNewOrderArray As New ArrayList

    Public Shared FFOrderDoNotIncludeInOrderArray As New ArrayList

    Public Shared FFOrderHT As New Hashtable

    Public Shared FFOrderDoNotIncludeHT As New Hashtable
indy500fanAuthor Commented:
Duh, I just need the new clause.  I had brainfade and wasn't thinkin clearly.

Thanks for your help!
Mike TomlinsonMiddle School Assistant TeacherCommented:
"Wrong" is really only relative to YOUR situation.

If those items only ever need ONE instance of them across all forms then it's fine.

You could then access them with:



If you need a seperate copy of each one for every instance of the form then this is not a viable approach.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.