title: Passing a '2 dimensional array' local variable to a class level variable
body: <p>I have a sub which reads an Excel file (X rows by 5 columns) and make a copy of its data into a String array called 'matrix' in VB.NET. I do need, however, to access of this array in some other subs as well. I was hoping to pass the array to a class level array variable and then retrieve info from that one instead. But I don't how to achieve this goal.</p>
  
  <pre><code>Public Sub ReadFromExcel()
          Dim excel As Application = New Application
          Try
              Dim wrkbook As Workbook = excel.Workbooks.Open(IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly.Location) &amp; _
          "EXCELFILE.xls")
          Dim sheet As Worksheet = wrkbook.Sheets(1)
          Dim cell As Range = sheet.UsedRange
          Dim LastRow As Long = 0
          sheet.Activate()
          With sheet
              LastRow = .Cells(.Rows.Count, 1).End(XlDirection.xlUp).Row
          End With
          Dim matrix(LastRow - 1, 4) As String
          For i As Integer = 2 To LastRow
              For j As Integer = 1 To 5
                  matrix(i - 1, j - 1) = cell(i, j).VALUE
              Next
          Next (i)
          wrkbook.Close()
          excel.Quit()
      Catch ex As Exception
          MessageBox.Show(ex.Message)
      End Try
  End Sub
  </code></pre>