473,382 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Help I am new to VB and have a program due

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
8 4988
albertw
267 100+
hi

made an example, maybe some use to you :)
Attached Files
File Type: zip flight.zip (2.0 KB, 574 views)
Nov 7 '06 #2
Unfortunalty I was unable to download the zip file. Could you briefly explain the code for me.
Nov 7 '06 #3
albertw
267 100+
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
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
albertw
267 100+
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
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
albertw
267 100+
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
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

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

Similar topics

4
by: PHPkemon | last post by:
Hi there, A few weeks ago I made a post and got an answer which seemed very logical. Here's part of the post: PHPkemon wrote: > I think I've figured out how to do the main things like...
6
by: wukexin | last post by:
Help me, good men. I find mang books that introduce bit "mang header files",they talk too bit,in fact it is my too fool, I don't learn it, I have do a test program, but I have no correct doing...
2
by: John Baker | last post by:
I find it highly annoying that MS Access tries to go online when I want to look at the help files. Is there a way to configure it so it just looks at my local helpfiles when I hit F1?
5
by: Bec | last post by:
I'm in desperate need of your help.. I need to build an access database and have NO idea how to do this.. Not even where to start.. It IS for school, and am not asking anyone to do my...
4
by: Tarique Jawed | last post by:
Alright I needed some help regarding a removal of a binary search tree. Yes its for a class, and yes I have tried working on it on my own, so no patronizing please. I have most of the code working,...
15
by: Buck Rogers | last post by:
Hi guys! Task 1: Write a program which presents a menu with 5 options. The 5th option quits the program. Each option should execute a system command using system(). Below is my humble...
7
by: tyler_durden | last post by:
thanks a lot for all your help..I'm really appreciated... with all the help I've been getting in forums I've been able to continue my program and it's almost done, but I'm having a big problem that...
2
by: Erik | last post by:
Hi Everyone, I'm having real problems compiling some source for eVC4++. The errors I am getting are below: It all seems to be centred around winsock. If I move the afsock.h reference to before...
6
by: HelpME | last post by:
I wrote a program in Vb.Net that was running fine. However I am unable to install it on a couple of machines. When i run it I get a windows error message that says My Project.exe has...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.