By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,057 Members | 1,401 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,057 IT Pros & Developers. It's quick & easy.

Help I am new to VB and have a program due

P: 9
I have to write a program that will do the following
Write a reservation system for an airline flight (based on problem #7 pages 406). Assume the airplane has 10 rows with 4 seats in each row. Use a two dimensional array of strings to maintain a seating chart with passengers’ names and another two dimensional control array to show available seats on the form (see example 2 page 380). In addition, create an array to be used as a waiting list for in case the plane is full. The waiting list should be “first come, first serve,” that is, people who are added early to the list get priority over those added later. Allow the user the following options:
1) Add a passenger to the flight
· Request a passenger’s name, do not process unless something is entered into the textbox
· If seats are available, user chooses a seat, do not allow user to assign to a seat already taken, nor to exit the process without selecting a seat.
· If no seat available, place the passenger on the wait list. If the wait list is full (10 passengers waiting) display a message that the flight is full


the problem i am having is assigning the passenger to at seat once one passenger has already been assigned. I am using a two dimensional array and i am not sure how to place the next passenger in the correct position of the array?

My source code is below

passenger = txtPassName.Text & " Row " & rowpos + 1 & " " & "Seat " & colpos + 1
If rowcount >= 9 And colcount >= 3 Then
MsgBox("All seats are filled. Your name will be placed on a seating chart")
Else
Do While SeatingChart(rowpos, colpos) < passenger

For rowcount = 0 To rowcount
For colcount = 0 To colcount
SeatingChart(rowcount, colcount) = passenger

Next
Next

Loop
rowpos += 1
colpos += 1
If (SeatingChart(rowpos, colpos) = passenger) And ((rowpos < rowcount) And (colpos < colcount)) Then
MsgBox("Seat already taken choose another seat")
Else
For i As Integer = rowcount - 1 To rowpos Step -1
For j As Integer = colcount - 1 To colpos Step -1
SeatingChart(1 + 1, j + 1) = SeatingChart(i, j)

Next
Next
SeatingChart(rowpos, colpos) = passenger
rowcount += 1
colcount += 1
End If
txtPassName.Clear()
txtPassName.Focus()

End If
Nov 7 '06 #1
Share this Question
Share on Google+
8 Replies


100+
P: 267
hi

made an example, maybe some use to you :)
Attached Files
File Type: zip flight.zip (2.0 KB, 538 views)
Nov 7 '06 #2

P: 9
Unfortunalty I was unable to download the zip file. Could you briefly explain the code for me.
Nov 7 '06 #3

100+
P: 267
hi

open a new project
place 3 textboxes, txtPassName, txtRow and txtSeat
place 1 listbox, lstWaiting
place 2 buttons, cmdProcess and cmdCancel


Expand|Select|Wrap|Line Numbers
  1. Option Base 1
  2. Const maxRow = 10
  3. Const maxSeat = 4
  4. Const maxList = 10
  5. Dim RowSeat(10, 4) As String
  6. Dim Seats As Integer
  7. Dim Waiting As Boolean
  8.  
  9. Private Sub cmdCancel_Click()
  10. If txtpassName.Text = vbNullString Then Exit Sub
  11. For r = 1 To maxRow
  12.     For s = 1 To maxSeat
  13.     p = InStr(1, RowSeat(r, s), "Row")
  14.         If p > 0 Then
  15.         passName = UCase(Left(RowSeat(r, s), p - 2))
  16.             If passName = UCase(txtpassName.Text) Then
  17.             r0 = Mid(RowSeat(r, s), p + 4, 1)
  18.             txtRow.Text = r0
  19.             p = InStr(1, RowSeat(r, s), "Seat")
  20.             s0 = Mid(RowSeat(r, s), p + 5, 1)
  21.             txtSeat.Text = s0
  22.             If MsgBox("Cancel the flight for " & vbNewLine & _
  23.             txtpassName.Text & " ?", vbYesNo + vbQuestion, "Cancel") = vbNo Then Exit Sub
  24.             RowSeat(r, s) = vbNullString
  25.             Reset
  26.             Seats = Seats - 1
  27.             Exit Sub
  28.             End If
  29.         End If
  30.     Next s
  31. Next r
  32.  
  33. End Sub
  34.  
  35. Private Sub cmdProcess_Click()
  36. If txtpassName.Text = vbNullString Or txtRow.Text = vbNullString Or txtSeat.Text = vbNullString Then Exit Sub
  37.     If Seats = (maxRow) * (maxSeat) Then
  38.     MsgBox "All seats are taken. " & vbNewLine & _
  39.     "This passenger will be put into" & vbNewLine & _
  40.     " the waitinglist.", vbOKOnly + vbExclamation, "Seats"
  41.         If lstWaiting.ListCount < maxList Then
  42.         lstWaiting.AddItem txtpassName.Text
  43.         Else
  44.         MsgBox "This flight is full.", vbOKCancel + vbCritical, "Flight"
  45.         End If
  46.         Reset
  47.         Exit Sub
  48.     End If
  49. passenger = txtpassName.Text & " Row " & txtRow.Text & " " & "Seat " & txtSeat.Text
  50. For r = 1 To maxRow
  51.     For s = 1 To maxSeat
  52.     p = InStr(1, RowSeat(r, s), "Row")
  53.         If p > 0 Then
  54.         passName = UCase(Left(RowSeat(r, s), p - 2))
  55.             If passName = UCase(txtpassName.Text) Then
  56.             r0 = Mid(RowSeat(r, s), p + 4, 1)
  57.             p = InStr(1, RowSeat(r, s), "Seat")
  58.             s0 = Mid(RowSeat(r, s), p + 5, 1)
  59.             MsgBox "This passenger has already been assigned to:" & vbNewLine _
  60.             & "Row " & r0 & " Seat " & s0, vbOKOnly + vbExclamation, "Seat"
  61.             txtRow.SetFocus
  62.             Exit Sub
  63.             End If
  64.         End If
  65.     Next s
  66. Next r
  67.  
  68. If RowSeat(txtRow.Text, txtSeat.Text) = vbNullString Then
  69.     RowSeat(txtRow.Text, txtSeat.Text) = passenger
  70.     Reset
  71.     Seats = Seats + 1
  72.     If Waiting = True Then lstWaiting.RemoveItem 0
  73. Else
  74.     MsgBox "This seat is taken. Choose another one.", vbOKOnly + vbExclamation, "Seats"
  75.     txtRow.SetFocus
  76. End If
  77. End Sub
  78.  
  79. Private Sub Form_Load()
  80. Seats = 0
  81. End Sub
  82.  
  83. Private Sub lstWaiting_Click()
  84. If lstWaiting.ListCount > 0 Then
  85. Reset
  86. txtpassName.Text = lstWaiting.List(0)
  87. Waiting = True
  88. End If
  89. End Sub
  90.  
  91. Private Sub txtpassname_Change()
  92. txtRow.Enabled = IIf(Len(txtpassName.Text) > 0, True, False)
  93. txtSeat.Enabled = IIf(Len(txtpassName.Text) > 0, True, False)
  94. End Sub
  95.  
  96. Private Sub Reset()
  97. txtpassName.Text = vbNullString
  98. txtRow.Text = vbNullString
  99. txtSeat.Text = vbNullString
  100. txtpassName.SetFocus
  101. End Sub
  102.  
  103. Private Sub txtRow_Change()
  104. If Val(txtRow.Text) > maxRow Then Exit Sub
  105. End Sub
  106.  
  107. Private Sub txtSeat_Change()
  108. If Val(txtSeat.Text) > maxSeat Then Exit Sub
  109. End Sub
  110.  
the code is to be copied and pasted...
it does what you want it to do.

enter the passengersname into txtpassName
enter the row in txtrow and seatnumber in txtseat
then press cmdProcess
to cancel a booking from the plane, enter the name and press cmdcancel
(row and seatnumber are exposed)
if no seats are available, up to 10 passengers may be put into the waitinglist (lstwaiting)
if any seats are cancelled, you can click in the listbox, where the topmost name is selected and put into txtpassname.
add row and seatnumber and press cmdprocess
if this passenger was accepted, the name will be removed from the waitinglist.

warnings are given for 2nd assignment of same name and if seats are no more available.

you may expand this program with a lot of other options, like e.g. a graphic seatdisplay

success
Nov 8 '06 #4

P: 9
WOW!!!!

This is great thank you soooo much. This is very helpful.

I actually constructed a contorl array of buttons to display seat assignments, thank you for the suggestion
Nov 8 '06 #5

100+
P: 267
WOW!!!!

This is great thank you soooo much. This is very helpful.

I actually constructed a contorl array of buttons to display seat assignments, thank you for the suggestion
hi

or you may create a number of labels (array - format) and give the label.background a different color when occupied. ?
Nov 8 '06 #6

P: 9
yea i started of with lables but then I thought it would be great if user could click the seat wanting to seat in and once clicked the locationof the button in the button array would be assigned to the seatassign array, but I have know clue how to do that I tried to add a click event to buttons but i didn't know how to pull out the buttons loc in array
Nov 8 '06 #7

100+
P: 267
yea i started of with lables but then I thought it would be great if user could click the seat wanting to seat in and once clicked the locationof the button in the button array would be assigned to the seatassign array, but I have know clue how to do that I tried to add a click event to buttons but i didn't know how to pull out the buttons loc in array
yes, you can use buttons, but label have a click-function also :)
you can make a single array of labels say from 1 to 40 and assign a tag as row/seatnumber
e.g: lblSeat(2) has a tag 0102, meaning row 01 and seat 02
lblSeat(23) has a tag 0503 etc
have your program look for tags and not indexnumbers
Nov 8 '06 #8

P: 2
Howdy,

Sorry for intruding, but I've got a similar problem:

I've got a VB6 assignment which uses Arrays and an Access dbase.

It's a six seater plane (two columns, 3 rows each.) I've got to display a seating chart (this is where the array probably comes in?) at all times, and I've got to do bookings (Fname, Lname and Seat no.)

The data must be stored in Access 2K (I'm guessing we use the ADO control here?)

The seating chart can use labels, RED for taken, GREEN for open. It doesn't have to display the passenger name.

When I exit the VB app, the data in the array will obviously go, that's why I hvae to save the seat assignments in Access. When I run the app, it should populate the chart with the seat assigments stored in the dbase.

We also have to have a passwd login screen, which was simple to do and is workng just fine. Call forms such as an about form which is easy.

Any ideas?


yes, you can use buttons, but label have a click-function also :)
you can make a single array of labels say from 1 to 40 and assign a tag as row/seatnumber
e.g: lblSeat(2) has a tag 0102, meaning row 01 and seat 02
lblSeat(23) has a tag 0503 etc
have your program look for tags and not indexnumbers
Dec 4 '06 #9

Post your reply

Sign in to post your reply or Sign up for a free account.