2 Replies - 922 Views - Last Post: 17 December 2013 - 08:18 AM Rate Topic: -----

#1 NotEnoughTimeInTheDay  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 16-December 13

Airline Reservation Help

Posted 16 December 2013 - 09:48 PM

Hey guys I'm working on a very basic airline reservation code. The user has to click either economy or first class and then it assigns them a seat (5 economy and 5 first class) until full. Here's what I have and I'm getting stumped! All the help is greatly appreciated. I am by no means an expert!
 Public Class frmAirlineReservationSystem
   Dim SvcFirst() As Integer = {1, 2, 3, 4, 5}
   Dim SvcEcon() As Integer = {6, 7, 8, 9, 10}
   Dim PickSeat As New Random()
   Dim EconUsed(SvcEcon.GetUpperBound(0)) As Boolean
   Dim FirstUsed(SvcFirst.GetUpperBound(0)) As Boolean
    Dim nextseat As Integer = 0

   Dim SeatEcon() As Integer
   Dim SeatFirst() As Integer
   Dim CountEcon As Integer
   Dim CountFirst As Integer

   Private Sub frmAirlineReservationSystem_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      txtPassengers.Text = ""

      lblBoarding.Visible = False
      txtPassengers.Visible = False
      CountEcon = 0
      CountFirst = 0
   End Sub

   Private Sub btnAssign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAssign.Click
      If radEconomy.Checked = False And radFirst.Checked = False Then
         MessageBox.Show("Please indicate First Class or Economy Seating.", "Missing Information", MessageBoxButtons.OK, MessageBoxIcon.Error)
      Else
         'get seat assignment from remaining seats if there are any
         Dim service As String = "None"
         If radEconomy.Checked = True Then
            For i = 0 To EconUsed.GetUpperBound(0)
               If EconUsed(i) = False Then
                  service = "Economy"
                  Exit For
               End If
            Next
            If service = "None" Then ' None open. If section full, offer option to switch section types
               MessageBox.Show("There are no economy seats left. If you wish you may choose first class and try again or wait for the next flight in 3 hours.", "Out of space", MessageBoxButtons.OK, MessageBoxIcon.Hand)
            End If
         ElseIf radFirst.Checked = True Then
            For i = 0 To FirstUsed.GetUpperBound(0)
               If FirstUsed(i) = False Then
                  service = "First"
                  Exit For
               End If
            Next
            If service = "None" Then ' None open. If section full, offer option to switch section types
               MessageBox.Show("There are no first class seats left. If you wish you may choose economy and try again or wait for the next flight in 3 hours.", "Out of space", MessageBoxButtons.OK, MessageBoxIcon.Hand)
            End If
         End If
         If service <> "None" Then
            Dim nextseat As Integer = 0
            nextseat = GetNextSeat(service)

            If service = "Economy" Then
               nextseat = SvcEcon(nextseat)
               SeatEcon(CountEcon) = nextseat
               CountEcon += 1
            Else
               nextseat = SvcFirst(nextseat)

               SeatFirst(CountFirst) = nextseat
               CountFirst += 1
            End If


            lblBoarding.Visible = True
            lblBoarding.Text = " ****  BOARDING PASS **** " & vbCrLf & vbCrLf &
                Today & vbCrLf & vbTab & service & "Seat #: " & nextseat

         End If

         txtPassengers.Text = ""
         txtPassengers.Visible = True
         txtPassengers.Text = "PASSENGERS FOR NEXT FLIGHT" & vbCrLf & "First Class:" & vbCrLf &
          "ID" & vbTab & "Seat"

         For i = 0 To SeatFirst.GetUpperBound(0)
            txtPassengers.AppendText(
               i & vbTab & SeatFirst(i))
         Next

         txtPassengers.AppendText(
         vbCrLf & "First Class:" & vbCrLf & "ID" & vbTab & "Seat")

         For i = 0 To SeatEcon.GetUpperBound(0)
            txtPassengers.AppendText(
               i & vbTab & SeatEcon(i))
         Next
      End If
      If (CountEcon + CountFirst) = 10 Then
         MessageBox.Show("There are no seats remaining for this flight. The next flight is in 3 hours.", "Out of space", MessageBoxButtons.OK, MessageBoxIcon.Hand)
      End If
   End Sub
   'reset with cancel, but do not modify any of the previous entries
   Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click

      radEconomy.Checked = False
      radFirst.Checked = False
      lblBoarding.Text = ""

   End Sub
   Function GetNextSeat(ByVal service As String) As Integer
      Dim nextSeat As Integer

      If service = "Economy" Then
         Do
            nextSeat = PickSeat.Next(0, 5)
         Loop Until EconUsed(nextSeat) = False
         EconUsed(nextSeat) = True
      ElseIf service = "First" Then
         Do
            nextSeat = PickSeat.Next(0, 5)
         Loop Until FirstUsed(nextSeat) = False
         FirstUsed(nextSeat) = True
      End If

      Return nextSeat
   End Function
End Class


This post has been edited by Atli: 16 December 2013 - 09:53 PM
Reason for edit:: Use [code] tags when posting code!


Is This A Good Question/Topic? 0
  • +

Replies To: Airline Reservation Help

#2 maj3091  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 299
  • View blog
  • Posts: 1,768
  • Joined: 26-March 09

Re: Airline Reservation Help

Posted 17 December 2013 - 05:53 AM

Welcome to the forum.

Couple of points:

1. This is VB.Net code, not VB6, so in the wrong place (don't duplicate the post, a mod will move it).
2. You need to detail what issues you have, that way someone know what they're going to be helping you with.
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Airline Reservation Help

Posted 17 December 2013 - 08:18 AM

This Tutorial may help
specifically the section that states that it is also possible to create and array that can be resized. I notice that you have a couple of these but I see nowhere where you are ever resizing them.

EDIT: Damn searchlight!, corrected the link to exclude search hilighting.

This post has been edited by CharlieMay: 17 December 2013 - 08:22 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1