Solved

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

Posted on 2008-06-26
4
1,058 Views
Last Modified: 2010-07-27
Friends,

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?

Regards,
Eric
Public Sub ProcessFFData(ByVal Lap As Integer, ByVal RunID As Integer)

        frmTimelineSerial.lvFF.Clear()

        frmTimelineSerial.lvFF.Columns.Add("No")

        frmTimelineSerial.FFOrderArray.Clear() 'If I try to run this or any of the following 2 lines, I get a NullReferenceException Error. 

        frmTimelineSerial.FFOrderDoNotIncludeHT.Clear()

        frmTimelineSerial.FFOrderHT.Clear()
 

        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)

                Next

            End Using

        End Using

    End Sub

Open in new window

0
Comment
Question by:indy500fan
  • 2
  • 2
4 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
Comment Utility
Either...

(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...
0
 

Author Comment

by:indy500fan
Comment Utility
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
0
 

Author Comment

by:indy500fan
Comment Utility
Duh, I just need the new clause.  I had brainfade and wasn't thinkin clearly.

Thanks for your help!
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
Comment Utility
"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:

    frmTimelineViewer.FFOrderArray

etc...

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

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now