|
-
Dec 22nd, 2006, 04:17 AM
#1
Thread Starter
New Member
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.
-
Dec 22nd, 2006, 10:24 AM
#2
Hyperactive Member
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?
-
Dec 22nd, 2006, 12:10 PM
#3
Thread Starter
New Member
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
-
Dec 22nd, 2006, 12:21 PM
#4
Re: Airline Program
Welcome to the forums 
 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:
'...
seat = InputBox("What is your seat number?")
If seat < 6 And seat > 0 Then
'...
... 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:
'...
Dim counter(1 To 5)
'...
... it's advicable to avoid using Variants. Rather declare it like this:
VB Code:
Dim counter(1 To 5) As Long 'or something...
-
Dec 22nd, 2006, 01:00 PM
#5
Thread Starter
New Member
Re: Airline Program
Cheers that makes that error dissapear now
-
Dec 22nd, 2006, 03:19 PM
#6
Hyperactive Member
Re: Airline Program
 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:
Select Case i_d ' Evaluate I_d.
Case "WallaceW468PO1"
Label1.Caption = "Wallace" '<- May be a label in the picturebox is what you want?
Case "LauderH48PO2"
' and so on
Case "CarnegieA468PO3"
'
Case "ScottW468PO4"
'
Case "DeBruisR468PO5"
Label1.Caption = "DeBruis" '<- May be a label in the picturebox is what you want?
Case Else
' so far no one
End Select
-
Dec 23rd, 2006, 07:03 AM
#7
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|