One and Two DIM arrays for VB reservations program??

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

One and Two DIM arrays for VB reservations program??

 
0
  #1
Nov 1st, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 25
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: One and Two DIM arrays for VB reservations program??

 
0
  #2
Nov 1st, 2008
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?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: One and Two DIM arrays for VB reservations program??

 
0
  #3
Nov 2nd, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 25
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: One and Two DIM arrays for VB reservations program??

 
0
  #4
Nov 2nd, 2008
I guess I'm still not following... From your code, you are creating an array correctly with the lines

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

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

  1. test(i)

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

[code=vb]
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
  1. MessageBox.Show(i & vbTab & output)

with

  1. 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.)
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 23
Reputation: 3Dees is an unknown quantity at this point 
Solved Threads: 0
3Dees 3Dees is offline Offline
Newbie Poster

Re: One and Two DIM arrays for VB reservations program??

 
0
  #5
Nov 2nd, 2008
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 ?
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 306
Reputation: timothybard is an unknown quantity at this point 
Solved Threads: 25
timothybard's Avatar
timothybard timothybard is offline Offline
Posting Whiz

Re: One and Two DIM arrays for VB reservations program??

 
0
  #6
Nov 2nd, 2008
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:

  1. Public Sub main()
  2. 'Code to create Seats boolean array
  3. Dim seats() As Boolean
  4.  
  5. 'Code to set the number of seats in the array
  6. Dim numSeats As Integer
  7. numSeats = 15
  8. ReDim seats(numSeats - 1)
  9.  
  10. 'Code to assign a seat
  11. Dim assignSeat As Integer
  12. assignSeat = 10
  13. seats(assignSeat - 1) = "True"
  14. assignSeat = 11
  15. seats(assignSeat - 1) = "True"
  16.  
  17. 'Code to unassign a seat
  18. Dim unassignSeat As Integer
  19. unassignSeat = 10
  20. seats(unassignSeat - 1) = "False"
  21.  
  22. 'Display seats
  23. Dim counter As Integer
  24. Dim seatsDisplay As String
  25. For counter = 0 To UBound(seats)
  26. seatsDisplay = seatsDisplay & "(" & counter + 1 & ") " & seats(counter) & " "
  27. Next
  28. MsgBox seatsDisplay
  29.  
  30. End Sub

I would recommend using functions to assign seats and display the seats.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC