title: How do I convert a two-dim array to a one-dim?
body: <p>the problem is that I first have to convert the two-dim  to a one-dim, then find the selected index and then convert again and then save the new index. after that I have to use the right string.format to show the right output.. I'm just confused =(</p>
  
  <p>In the program there are two text boxes that ask for "row" and "col" size and then you press the button and a list box shows</p>
  
  <pre><code>...............................................................................................................................
  Row...Col.......................................................................................................................................
  1------1----Vacant ........................................................................
  1......2.......Vacant...................................................................................................
  1......3.......Vacant....................................................................................................................................
  2------1----Vacant.........................................................................................................................
  2......2.......Vacant....................................................................................................................................
  2......3.......Vacant..........................................................................................................................................................
  3------1----Vacant....................................................................................................................................
  etc.............................................................................................................................................................
  </code></pre>
  
  <p>and when I double click one line it has to say "Reserved"
  Can someone help me what to do this please?</p>
  
  <p>This is my project folder so far here you can see my <a href="http://www.mediafire.com/?o6ol8crpx7x9rno" rel="nofollow noreferrer">failed code</a> and <a href="http://www.mediafire.com/?vfr3bvfyk673bmd" rel="nofollow noreferrer">this is my assignment</a></p>
  
  <p>This is how the program is supposed to look like in the end
  <img src="https://i.stack.imgur.com/xILHD.jpg" alt="http://i29.tinypic.com/risq6r.jpg"></p>
  
  <pre><code>'Created by: Hans Elias Juneby
  'Started: July 10, 2010 Completed July 0, 2010
  
  Public Class MainFrame
  '''&lt;summary&gt;
  ''' Enum used for choices of showing results
   ''' &lt;/summary&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
   Private Enum UpdateOptions
    ShowAllSeats               'reserved and vacant seats
    ShowOnlyVacantSeats        'Only vacant seats   
    ShowOnlyReservedSeats      'Only reserved seats
  End Enum
  
  'Instance variables
  Private bookingObj As SeatBooking = New SeatBooking()
  Private showOptions As UpdateOptions = UpdateOptions.ShowAllSeats
  
  '''&lt;summary&gt;
  ''' Default constructor
  ''' Initialize components and do other preparations.
  ''' This method is called automatically before the form is made visible
  ''' &lt;/summary&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Sub New()
  
    ' This call is required by the Windows Form Designer.
    InitializeComponent()
  
    ' My initialization
    InitializeControlvalues()
    UpdateResults()
  End Sub
  
  '''&lt;summary&gt;
  ''' Organize initiations
  ''' Fill comboboxes with options (strings), set default values, etc
  ''' &lt;/summary&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Private Sub InitializeControlvalues()
    FillUnitTypeList()
    lstUnits.SelectedIndex = -1
    cmbShowOptions.Items.AddRange([Enum].GetNames(GetType(UpdateOptions)))
    cmbShowOptions.SelectedIndex = 0
    rbtnLetters.Checked = True
    ' txtNumOfSeats.Text = bookingObj.GetMaxCols.ToString() 'default values
    ' txtNumOfRows.Text = bookingObj.GetMaxRows.ToString() 'default values
    lblNumVacants.Text = String.Empty 'default values  
    lblTotal.Text = String.Empty 'default values
    lblPercent.Text = String.Empty 'default values
   End Sub
  
   ''' &lt;summary&gt;
   ''' Clear listbox, format new strings with the help of the bookingObj and
   '''fill in the box.
   '''  &lt;/summary&gt;
   ''' &lt;remarks&gt;&lt;/remarks&gt;
   Private Sub UpdateResults()
  
   End Sub
  
   '''&lt;summary&gt;
   ''' Helper function that returns a string containing a string "** Reserved **" or
   '''"Vacant" or no text according the value in showOptions. THe UpdateResults
   ''' calls this function in detecting which string to show in the listbox
   ''' &lt;/summary&gt;
  ''' &lt;param name="row"&gt;Input&lt;/param&gt;
  ''' &lt;param name="col"&gt;Input&lt;/param&gt;
  ''' &lt;returns&gt;A formatted string as explained above&lt;/returns&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Private Function GetReservationStatusString() 
  
    Select Case (cmbShowOptions.SelectedIndex)
  
       Case 0
  
       Case 1
  
       Case 2
  
    End Select
  
   End Function
  
  'Fills values in the combobox
   Private Sub FillUnitTypeList()
    Dim units As String() = {"Bus Seats", "Train Seats", "Plane Seats"}
    cmbUnitType.Items.AddRange(units)
    cmbUnitType.SelectedIndex = 0
  
  End Sub
  
  Private Sub cmbShowOptions_SelectedIndexChange(ByVal sender As System.Object, ByVal e As System.GC)
    showOptions = DirectCast(cmbShowOptions.SelectedIndex, UpdateOptions)
    UpdateResults()
  End Sub
  
  
     Private Sub btnMatrix_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnMatrix.Click
    Dim SeatBooking As New SeatBooking
  
    bookingObj.GetMaxRows.ToString()
    bookingObj.GetMaxCols.ToString()
  
    lblTotal.Text = txtNumOfRows.Text * txtNumOfSeats.Text
   End Sub
  
  
   ''' &lt;summary&gt;
   ''' Event-handler for the double-click event.
    ''' Reserve/cancel the seat chosen in the listbox (call   bookingObj.SetRowAndCOlumnValue),
   ''' only if the showOption is Show ALL; otherwise, give an error message and do nothing.
  ''' &lt;/summary&gt;
  ''' &lt;param name="sender"&gt;sender-object from the caller&lt;/param&gt;
  ''' &lt;param name="e"&gt;EventArgs object from the caller&lt;/param&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Private Sub lstUnits_DoubleClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstUnits.DoubleClick
  
    lblNumVacants.Text = lblTotal.Text - 1
    Return
  End Sub
  
  ''' &lt;summary&gt;
  ''' Event-handler method for change in the radiobutton
  ''' &lt;/summary&gt;
  ''' &lt;param name="sender"&gt;&lt;/param&gt;
  ''' &lt;param name="e"&gt;&lt;/param&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
   Private Sub rbtnLetters_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles rbtnLetters.CheckedChanged
     UpdateResults()
     Dim A As Integer = 65
      Dim myChar As Char
     Dim col As Integer = 0
     myChar = Convert.ToChar((A + col))
  
   End Sub
  
   Private Sub UpdateUnit()
    'Dim strText As String = bookingObj.GetUnitName(cmbUnitType.SelectedIndex)
    ' lblVacantUnits.Text
   End Sub
  End Class
  </code></pre>
  
  <p>then the SeatBook class:</p>
  
  <pre><code>'Created by: Hans Elias Juneby
  'Started: July 10, 2010 Completed July 0, 2010
  
  Public Class SeatBooking
  
  Private array As Double()    'Declaration of the array 
  Private lastIndex As Integer = 0    'last filled position (lastIndex+1 = number of items 
  
  '''&lt;summary&gt;
  ''' Create (or recreate) the matrix with the given size
  ''' &lt;/summary&gt;
  '''&lt;param name="rowSize"&gt;Number of rows&lt;/param&gt;
  ''' &lt;param name="colSize"&gt;Number of columns&lt;/param&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Public Sub CreateArray(ByVal rowSize As Integer, ByVal colSize As Integer)
     Debug.Assert(rowSize &gt;= 0)      'Program execution halts here in case size is &lt;0; 
     array = New Double(rowSize - 1) {}
    Debug.Assert(colSize &gt;= 0)      'Program execution halts here in case size is &lt;0; 
    array = New Double(colSize - 1) {}
    Dim seatMatrix As Boolean(,)
    seatMatrix = New Boolean(rowSize, colSize) {}
  
  
  
    End Sub
  '''&lt;summary&gt;
  ''' Calculate the total number of elements(row*col)
  ''' &lt;/summary&gt;
  '''&lt;returns&gt;The total number of elements&lt;/returns&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetMaxCount() As Integer
  
  End Function
  
  '''&lt;summary&gt;
  ''' Check if a seat in a specific row and column is reserved.
  ''' &lt;/summary&gt;
  '''&lt;param name="row"&gt;given row&lt;/param&gt;
  '''&lt;param name="col"&gt;given col&lt;/param&gt;
  '''&lt;returns&gt;True if the seat is reserved and false otherwise&lt;/returns&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Public Function IsReserved(ByVal row As Integer, ByVal col As Integer)
  
  End Function
  
  '''&lt;summary&gt;
  ''' Make a new reservation or cancel an existing. This process is onde by
  ''' reversing the boolean value in the given position in the matrix, from true to 
  ''' false (reverse the seat) or vice versa(Cancel the reservation)
  ''' &lt;/summary&gt;
  '''&lt;param name="row"&gt;given row&lt;/param&gt;
  '''&lt;param name="col"&gt;given col&lt;/param&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Public Sub Reserve(ByVal row As Integer, ByVal col As Integer)
  
  End Sub
  
  
  '''&lt;summary&gt;
  ''' Thenumber of rows in the Matrix
  ''' &lt;/summary&gt;
  ''' &lt;returns&gt;The number of rows&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetMaxRows() As Integer
     Dim colsize As Integer = MainFrame.txtNumOfSeats.Text
     Dim rowsize As Integer = MainFrame.txtNumOfRows.Text
  
  
  
    CreateArray(colsize, rowsize)
  
    For i As Integer = 0 To array.Length - 1
  
       MainFrame.lstUnits.Items.Add("----" &amp; i &amp; "---" &amp; GetMaxCols.ToString.Length)
    Next
  End Function
  
  '''&lt;summary&gt;
  ''' Thenumber of columns in the Matrix
  ''' &lt;/summary&gt;
  ''' &lt;returns&gt;The number of columns&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetMaxCols() As Integer
     Dim colsize As Integer = MainFrame.txtNumOfSeats.Text
    Dim rowsize As Integer = MainFrame.txtNumOfRows.Text
  
    CreateArray(rowsize, colsize)
  
    For h As Integer = 0 To array.Length - 1
  
    Next
  
  End Function
  
  '''&lt;summary&gt;
  ''' The method first finds the first vacant pos in the matrix (row, col)
  ''' and then calls another method MatrixIndexToVectorialIndex that determines which
  ''' position the element has if the matrix was rolled out into a one-dimensional
  ''' array. In a 3x3 matrix, the element in position (1,1) has an index 4 in
  ''' one-dimensional array. The method is useful when updating the listbox in the
  ''' GUI which contains a one-dimensional array of strings. The method determines which
  ''' position (row,col) in the matrix corresponds to an item (row) in the listbox.
  '''  &lt;/summary&gt;
  '''&lt;returns&gt;The index, considering the matrix as one long vector, to the first vacant
  ''' position ( the first False value). A value -1 is returned if no vacant element is
  ''' found&lt;/returns&gt;
  '''&lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetFirstVacantPosition() As Integer
  
  End Function
  
  ''' &lt;summary&gt;
  ''' Determine a corresponding index for an element at (row,col) in a one-dimensional
  ''' presentation of the matrix. Think of the matrix as beeing rolled out into a one-dim
  ''' array. In a 3x3 matrix, the element in position (1,1) has an index 4 in
  ''' one-dimensional array.
  '''        20  11  22
  '''        33  41  55
  '''        60  7   99   Consider value (1,1)=41
  ''' The above matrix can now be represented as one dimensional array. This makes it
  ''' easier to update the listbox in the GUI.
  '''        20  11  22  33  41  55  60   7   99    value(4)=41
  '''  Index  0   1   2   3   4   5   6   7   8
  '''Hence, index (1,1) in the matrix corresponds to row 4 in the listbox (one-dim array)
  ''' &lt;/summary&gt;
  ''' &lt;param name="row"&gt;&lt;/param&gt;
  ''' &lt;param name="col"&gt;&lt;/param&gt;
  ''' &lt;returns&gt;The new index as explained above&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function MatrixIndexToVectorIndex(ByVal row As Integer, ByVal col As Integer)  
  
  End Function
  
   ''' &lt;summary&gt;
  ''' Determines the index in the matrix (row,col) that corresponds to a given 
   ''' index in a one-dim array (listbox). This method actually is reverse process of
  ''' the method MatrixIndexToVectorIndex (see above). The parameter row contains
  ''' the input, i.e. index of the element in a one-dim array. The results (row and col)
  ''' are saved and sent back to the caller via the ref variables row,col.
  ''' &lt;/summary&gt;
  ''' &lt;param name="row"&gt;Input and output parameter&lt;/param&gt;
  ''' &lt;param name="col"&gt;Output parameter&lt;/param&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Sub VectorIndexToMatrixIndex(ByRef row As Integer, ByRef col As Integer)
  
  End Sub
  
  ''' &lt;summary&gt;
  ''' This function receives an index in a one-dim array (e.g. listbox) and calls 
  ''' the method VectorIndexToMatrixIndex to fin the same position in the matrix.
  ''' It then calls the function Reserve to either reserve or cancel a booking.
  ''' (If False value is saved in the element, it reserves the seat by changing
  ''' the value to True, and vice-versa).
  ''' &lt;/summary&gt;
  ''' &lt;param name="oneDimListIndex"&gt;&lt;/param&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Sub SetRowAndColumnValue(ByVal oneDimListIndex As Integer) 
  
  End Sub
  
  ''' &lt;summary&gt;
  ''' Calculate the total number of the reserved seats, i.e. the total
  ''' number of the True values in the matrix.
  ''' &lt;/summary&gt;
  ''' &lt;returns&gt;Number of reserved seats&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetNumOfReservedSeats() As Integer 
  
  End Function
  
  ''' &lt;summary&gt;
  ''' Calculate the total number of the vacant seats, i.e the total
  ''' number of the False values in the matrix.        
  ''' &lt;/summary&gt;
  ''' &lt;returns&gt;number of vacant seats&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function GetNumOfVacantSeats() As Integer
  
  End Function
  
  ''' &lt;summary&gt;
  ''' Relation between the reserved seats and the total number of seats in percent.
  ''' &lt;/summary&gt;
  ''' &lt;returns&gt;Percent of Reservation&lt;/returns&gt;
  ''' &lt;remarks&gt;&lt;/remarks&gt;
  Public Function PercentOfReservation() As Double
  
  End Function
  End Class
  </code></pre>