Results 1 to 7 of 7

Thread: Airline Program

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    4

    Question Airline Program

    Hello, I'm trying to create a program wich has one picture box, 2 input boxes and a start button, The code is for an airline program which when you enter the i.d's of people into an input box the i.d's should be displayed on screen unless the i.d's aren't there, it should also take the name from the i.d's and display them in the picture box too, there is also there is another input box for the seat number which should let a person enter a seat number between 1 and 5 and if higher than this a message box will be displayed, This is the code I have so far, any help on improveing it will be appricated

    Private Sub cmdstart_Click()

    Dim i_d
    Dim seat As Integer
    Dim nme As String

    picdisplay.Print "Booking confrimation"
    picdisplay.Print "Flight number = HA468"

    Do
    i_d = InputBox("What is your I.D?")
    If i_d = "WallaceW468PO1" Or i_d = "LauderH48PO2" Or i_d = "CarnegieA468PO3" Or i_d = "ScottW468PO4" Or i_d = "DeBruisR468PO5" Then
    picdisplay.Print "ID"; i_d
    End If

    If i_d <> "WallaceW468PO1" Or i_d <> "LauderH48PO2" Or i_d <> "CarnegieA468PO3" Or i_d <> "ScottW468PO4" Or i_d <> "DeBruisR468PO5" Then
    MsgBox ("Please Re-enter your i_d")
    End If
    Loop Until i_d = "WallaceW468PO1" Or i_d = "LauderH48PO2" Or i_d = "CarnegieA468PO3" Or i_d = "ScottW468PO4" Or i_d = "DeBruisR48PO5"

    --in this section there should be code to display the name in the picture box which is taken from th i.d for exzample ScottW468PO4 should display the name Scott.


    Do
    Dim counter(1 To 5)
    seat = InputBox("What is your seat number?")
    If seat < 6 And seat > 0 Then
    picdisplay.Print "Seat Number"; seat
    End If

    If seat > 5 Or seat < 1 Then
    MsgBox ("Please re-enter your seat number")
    End If
    Loop Until seat < 6 And seat > 0


    End Sub

    Thanks!!
    Last edited by S.J.Roger; Dec 22nd, 2006 at 12:15 PM.

  2. #2
    Hyperactive Member singularis's Avatar
    Join Date
    Nov 2006
    Location
    Over There!
    Posts
    372

    Re: Airline Program

    1) please use VB tags when posting large chunks of code as it is easier to read

    2) Do you want people to write code for you ?

    3) How can you improve it and how does it need to be improved?
    If what I said was helpful, give me rep!

    My Complete Games: -- 2D Zone (Space Shooter game) || _2D Zone 2_ || Ninja Blob (2D platformer) || Dren (Co-op up to 4 player base defence game)

    My Projects: -- The Dread Engine (2D VB game Engine) || A* Path Finding


    An excellent site for learning DirectX7, 8 & 9 (for VB6, C# & VB.net) would be: directx4vb.vbgamer.com --- For my projects and games see: pieper.freehostia.com

  3. #3

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    4

    Question Re: Airline Program

    Sorry, I'll use vb tags next time, and yes thanks I would like code written for the program and on improving it, I mean like shorten the amount of code used for the program to work or just the code needed for the name

  4. #4
    PowerPoster gavio's Avatar
    Join Date
    Feb 2006
    Location
    GMT+1
    Posts
    4,462

    Re: Airline Program

    Welcome to the forums
    Quote Originally Posted by S.J.Roger
    ... I'll use vb tags next time...
    You can edit your post (the code is easier to read)

    Just few suggestions:
    VB Code:
    1. '...
    2. seat = InputBox("What is your seat number?")
    3. If seat < 6 And seat > 0 Then
    4. '...
    ... that could be a problem. Since "seat" is numerical (Integer), user can (still) enter "blah" or some other non-numerical value and you'll get a 'Type Mismatch' error (cause you're trying to write into an Integer). When you're reading from InputBox, always save it into a String (you never know how *smart* your users are), check if it's numerical (if you need it to be) - perheps with the IsNumeric() function - and continue/not.
    VB Code:
    1. '...
    2. Dim counter(1 To 5)
    3. '...
    ... it's advicable to avoid using Variants. Rather declare it like this:
    VB Code:
    1. Dim counter(1 To 5) As Long 'or something...

  5. #5

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    4

    Re: Airline Program

    Cheers that makes that error dissapear now

  6. #6
    Hyperactive Member
    Join Date
    Dec 2006
    Location
    Jar, Norway
    Posts
    372

    Re: Airline Program

    Quote Originally Posted by S.J.Roger
    --in this section there should be code to display the name in the picture box which is taken from th i.d for exzample ScottW468PO4 should display the name Scott.
    Usually is the InStr-function used to see if some text has specific content.
    In your case Select Case is more useful. (As long as only five options of names are present)
    VB Code:
    1. Select Case i_d   ' Evaluate I_d.
    2.   Case "WallaceW468PO1"
    3.     Label1.Caption = "Wallace" '<- May be a label in the picturebox is what you want?
    4.   Case "LauderH48PO2"
    5.     ' and so on
    6.   Case "CarnegieA468PO3"
    7.     '
    8.   Case "ScottW468PO4"
    9.     '
    10.   Case "DeBruisR468PO5"
    11.     Label1.Caption = "DeBruis" '<- May be a label in the picturebox is what you want?
    12.   Case Else
    13.     ' so far no one
    14. End Select

  7. #7

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Posts
    4

    Talking Re: Airline Program

    Thank you, I have completed the program now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width