[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2008-06-26
4
Medium Priority
?
1,068 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 2000 total points
ID: 21877405
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
ID: 21877449
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
ID: 21877491
Duh, I just need the new clause.  I had brainfade and wasn't thinkin clearly.

Thanks for your help!
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 21877504
"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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

650 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