Hi,
I could do with some help please, worked on this all week and still do not know where to start. i need to wirte a program starting with a one dim array in one vb project then use a two dim array to do the same in a new vb project. I have tried a few options but with no valuable success or understanding. The last code i tried was:

Public Sub TestArray()
        Dim output As String = ""
        Dim test() As Boolean
        test = New Boolean(0 To 10) {}
        For i As Integer = 0 To test.GetUpperBound(0)
            If i >= 0 Then
                output &= (test(i))
                MessageBox.Show(i & vbTab & output)
            End If
        Next
    End Sub

Just to ensure i could create the array but i haven't manage to move from there. Any advice? do you think i need a resizeble array, please any advice will be helpfull.

The problem:

A manager in a transport company has asked you to make a program that facilitates booking of seats in their passenger buses. She is well aware of the fact that you are a beginner in programming and therefore does not expect you to make an advanced application. She has many ideas but she agrees with our plans to develop the application in different versions beginning with a simple one and then optimizing it in subsequent versions.
Seats are assumed to be numbered from 1 in the front row to a number in the last row.
Their transport equipments have different seating plans and passenger capacities.

Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.

Edited 3 Years Ago by Nick Evan: Fixed formatting

I guess I don't know what you need help with. Do you need to know how to use a 2-d array? The problem you posted does not required a 2-d array.

It looks like you understand how to use a 1-d array. As far as using a resizable array, since you don't know how many elements will end up being in the array, I highly recommend using a resizable array.

Can you be more specific on what you need help with?

Thanks for the feed back,
I think i should be able to create the array however, i need help displaying the elements of the arry from a class into a list box on a form. Basically its getting the elements from a class to a module to be displayed in a list box.

I guess I'm still not following... From your code, you are creating an array correctly with the lines

Dim test() As Boolean
test = New Boolean(0 To 10) {}

To read an element from the array, you simply put the index of the element in the parenthesis:

test(i)

With the following code, you are correctly looping through all the elements in the array:

For i As Integer = 0 To test.GetUpperBound(0)
  If i >= 0 Then
    output &= (test(i))
    MessageBox.Show(i & vbTab & output)
  End If
Next
[/vb]

However, I don't know what the MessageBox class is.  If you replace
[code=vb]
    MessageBox.Show(i & vbTab & output)

with

msgbox i & vbtab & Output

Then a message box should appear with the appropriate output.

As far as displaying the elements of an array that is within an instance of class, I would need to know more specifics about the class to help you retrieve the element (is it a standard class or one that you created, what are its properties, etc.)

Thanks again and i will try to explain better.
consider this:

Public Class ArrayTest
    Private test() As Boolean

Public Sub createArray()
test = New Boolean(0 To 10) {}
end sub
end class

Public Class MainFrame (Form class)
Public Sub New()

        InitializeComponent()

        'initialization
        InitializeMore()
    End Sub
Private arrayTest As New ArrayTest() 

public Sub displayresults()
For i As Integer = 0 To arraytest.Length() - 1 

dim rst as string("{0}{1}", i &vbtab & arrayteat(i))

lstresult.items.add(rst)
next
end sub

hope this gives an idea of what i am trying to do not sure if i am right.
the above method does not work, consider the original thread :
Use a one-dimensional array (also called a vector) with elements containing
values of type Boolean to store reservation information. When a seat is to be reserved, a True value should be saved in the array at the position equal to the seat number minus one. This is because the array is indexed from zero, while seat numbers begin with 1. All vacant seats get a False value in the array.
how else could i approach this ?

Edited 3 Years Ago by Nick Evan: Fixed formatting

What is the purpose of having the class ArrayTest? I would recommend just having the array in the Sub New().

Please take a look at this code:

Public Sub main()
  'Code to create Seats boolean array
  Dim seats() As Boolean
  
  'Code to set the number of seats in the array
  Dim numSeats As Integer
  numSeats = 15
  ReDim seats(numSeats - 1)
  
  'Code to assign a seat
  Dim assignSeat As Integer
  assignSeat = 10
  seats(assignSeat - 1) = "True"
  assignSeat = 11
  seats(assignSeat - 1) = "True"
  
  'Code to unassign a seat
  Dim unassignSeat As Integer
  unassignSeat = 10
  seats(unassignSeat - 1) = "False"
  
  'Display seats
  Dim counter As Integer
  Dim seatsDisplay As String
  For counter = 0 To UBound(seats)
    seatsDisplay = seatsDisplay & "(" & counter + 1 & ") " & seats(counter) & " "
  Next
  MsgBox seatsDisplay

End Sub

I would recommend using functions to assign seats and display the seats.

This question has already been answered. Start a new discussion instead.