Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

subroutine not ending

ndifrekendifreke Member Posts: 49
i have been working on a personal assignment.well my problem is my subroutine refuses to exit after execution.I use qb4.5 and another is i cant exit a loop wen i have set the conditions.below is the source code .pls correct me anywhere.(i probably have bad programming practice...)well
.
.
.
.' this program leeps record of occupied and available seats in an airline.
'this is an airline reservation system.the file system implemented is RANDOM.
' variables used
' recNo% - records number for file
' person$ - stores name of passengers
' screen - helps control display of prints
' record name is "SEATS"
' problem def>.. the airplane as 40 rows with six seats labeled A to F for each row
' the program allows various choices of action by the operator.
' choices available are
' 1.) assigning of seats to passengers
' 2.) displayinhg of available seats
' 3.) displaying of occupied seats.
' 4.) initializing or reseting of record

TYPE recordstructure
a AS STRING * 20
b AS STRING * 20
C AS STRING * 20
d AS STRING * 20
e AS STRING * 20
f AS STRING * 20
END TYPE
DIM seatloc AS recordstructure
CLS
OPEN "plane.dat" FOR RANDOM AS #1

GOSUB initializeimages
PRINT TITLE$

DO
GOSUB PRINTMENU
GOSUB INPUTCHOICE
ON choice GOSUB assignseat, displayavailableseat, displaypassengersseat, initializerecord, displayall, TERMINATE
LOOP WHILE INKEY$ <> CHR$(27)
END
'********** intilize images *******
initializeimages:
LET TITLE$ = " AIRLINE RESERVATION SYSTEM "
LET COLHEAD$ = "SEAT A SEAT B SEAT C SEAT D SEAT E SEAT F"
LET format$ = " "
RETURN
'************ MENUS ****************

PRINTMENU:
PRINT
PRINT
PRINT " 1.) ASSIGN SEAT TO PASSENGER"
PRINT " 2.) DISPLAY AVAILABLE SEATS"
PRINT " 3.) DISPLAY PASSENGERS WITH SEAT"
PRINT " 4.) INITIALIZE IMAGES"
PRINT " 5.) PRINT ALL DATA"
PRINT " 6.) END APPLICATION"
PRINT
PRINT
PRINT " SELECT OPTION (1-5)";
RETURN

'********** CHOICE **********
INPUTCHOICE:
DO WHILE choice < 1 OR choice > 5
INPUT choice$
LET choice = VAL(choice$)
LOOP
RETURN
'**** ASSIGN SEAT **********
assignseat:
PRINT " ASSIGN SEAT TO PASSENGER/CUSTOMER "
DO
GOSUB enterpsgrname
GOSUB searchseat
IF empty = 0 THEN GOSUB writedata
CLS
PRINT seatloc.a; CHR$(197); seatloc.b; CHR$(197); seatloc.C; CHR$(197); seatloc.d; CHR$(197); seatloc.e; CHR$(197); seatloc.f
LET C$ = INPUT$(1)
LOOP WHILE C$ <> CHR$(27)
RETURN

'*********** DISPLAY SEAT AVALIABLE ********
displayavailableseat:
CLS

LET recno = 0
DO WHILE recno <= 40
recno = recno + 1
GET #1, recno, seatloc
IF seatloc.a = "available" THEN
PRINT recno; "A", seatloc.a

ELSEIF seatloc.b = "available" THEN
PRINT recno; "B", seatloc.b

ELSEIF seatloc.C = "available" THEN
PRINT recno; "C", seatloc.C

ELSEIF seatloc.d = "available" THEN
PRINT recno; "D", seatloc.d

ELSEIF seatloc.e = "available" THEN
PRINT recno; "E", seatloc.e

ELSEIF seatloc.f = "available" THEN
PRINT recno; "F", seatloc.f

END IF
LOOP
RETURN
'*********** PASSENGERS WITH SEATS ********
displaypassengersseat:
LET recno = 0
DO WHILE NOT EOF(1)
recno = recno + 1
GET #1, recno, seatloc
IF seatloc.a <> "available" THEN PRINT recno; "A", seatloc.a
IF seatloc.b <> "available" THEN PRINT recno; "B", seatloc.b
IF seatloc.C <> "available" THEN PRINT recno; "C", seatloc.C
IF seatloc.d <> "available" THEN PRINT recno; "D", seatloc.d
IF seatloc.e <> "available" THEN PRINT recno; "E", seatloc.e
IF seatloc.f <> "available" THEN PRINT recno; "F", seatloc.f
LOOP
RETURN

'******** INITIALIZE FILE *********
initializerecord:
CLS
PRINT "THIS WILL DELETE ALL RECORDS!"
PRINT : PRINT "DO YOU WANT TO PROCEED (y/n)"
INPUT "", C$
IF C$ = "y" OR C$ = "Y" THEN
LET recno = 0
DO WHILE recno <= 40
LET recno = recno + 1
GET #1, recno, seatloc
LET seatloc.a = "available"
LET seatloc.b = "available"
LET seatloc.C = "available"
LET seatloc.d = "available"
LET seatloc.e = "available"
LET seatloc.f = "available"
PUT #1, recno, seatloc
LOOP
ELSE
END IF
RETURN
'************* write data to file *************
writedata:
PUT #1, recno, seatloc
RETURN
'************ ENTER PASSENGERS NAME **********
enterpsgrname:
LOCATE , , 1 ' SET CURSOR TO VISIBLE
LINE INPUT "name of passenger"; psgrname$


RETURN
'************** search record **********
searchseat:
LET recno = 0 AND count = 0
DO WHILE switch = 1 OR count <= 40
recno = recno + 1: count = count + 1
GET #1, recno, seatloc
IF seatloc.a = "available" THEN
LET empty = 1 AND seatloc.a = psgrname$
ELSEIF seatloc.b = "available" THEN LET empty = 1 AND seatloc.b = psgrname$
ELSEIF seatloc.C = "available" THEN LET empty = 1 AND seatloc.C = psgrname$
ELSEIF seatloc.d = "available" THEN LET empty = 1 AND seatloc.d = psgrname$
ELSEIF seatloc.e = "available" THEN LET empty = 1 AND seatloc.e = psgrname$
ELSEIF seatloc.f = "available" THEN LET empty = 1 AND seatloc.f = psgrname$
END IF
LOOP

displayall:
CLS
FOR i = 1 TO 40
GET #1, i, seatloc
PRINT USING format$; seatloc.a; seatloc.b; seatloc.C; seatloc.d; seatloc.e; seatloc.f
NEXT i
RETURN
'************* END SESSION **************
TERMINATE:
END
RETURN

*************
well thats that.the system is a plane seat reservation system implementing random file management.it is supposed to help the user know wen a seat is occupied and where to fit a passenger.the plane as 40 rows with six seats in each row namjed A-F.

thanks for whtever help u render .one more how do i use this heaven"s mailbos.



















Comments

  • GaashiusGaashius Member Posts: 349
    : i have been working on a personal assignment.well my problem is my subroutine refuses to exit after execution.I use qb4.5 and another is i cant exit a loop wen i have set the conditions.below is the source code .pls correct me anywhere.(i probably have bad programming practice...)well
    : .
    : .
    : .
    : .' this program leeps record of occupied and available seats in an airline.
    : 'this is an airline reservation system.the file system implemented is RANDOM.
    : ' variables used
    : ' recNo% - records number for file
    : ' person$ - stores name of passengers
    : ' screen - helps control display of prints
    : ' record name is "SEATS"
    : ' problem def>.. the airplane as 40 rows with six seats labeled A to F for each row
    : ' the program allows various choices of action by the operator.
    : ' choices available are
    : ' 1.) assigning of seats to passengers
    : ' 2.) displayinhg of available seats
    : ' 3.) displaying of occupied seats.
    : ' 4.) initializing or reseting of record
    :
    : TYPE recordstructure
    : a AS STRING * 20
    : b AS STRING * 20
    : C AS STRING * 20
    : d AS STRING * 20
    : e AS STRING * 20
    : f AS STRING * 20
    : END TYPE
    : DIM seatloc AS recordstructure
    : CLS
    : OPEN "plane.dat" FOR RANDOM AS #1
    :
    : GOSUB initializeimages
    : PRINT TITLE$
    :
    : DO
    : GOSUB PRINTMENU
    : GOSUB INPUTCHOICE
    : ON choice GOSUB assignseat, displayavailableseat, displaypassengersseat, initializerecord, displayall, TERMINATE
    : LOOP WHILE INKEY$ <> CHR$(27)
    : END
    : '********** intilize images *******
    : initializeimages:
    : LET TITLE$ = " AIRLINE RESERVATION SYSTEM "
    : LET COLHEAD$ = "SEAT A SEAT B SEAT C SEAT D SEAT E SEAT F"
    : LET format$ = " "
    : RETURN
    : '************ MENUS ****************
    :
    : PRINTMENU:
    : PRINT
    : PRINT
    : PRINT " 1.) ASSIGN SEAT TO PASSENGER"
    : PRINT " 2.) DISPLAY AVAILABLE SEATS"
    : PRINT " 3.) DISPLAY PASSENGERS WITH SEAT"
    : PRINT " 4.) INITIALIZE IMAGES"
    : PRINT " 5.) PRINT ALL DATA"
    : PRINT " 6.) END APPLICATION"
    : PRINT
    : PRINT
    : PRINT " SELECT OPTION (1-5)";
    : RETURN
    :
    : '********** CHOICE **********
    : INPUTCHOICE:
    : DO WHILE choice < 1 OR choice > 5
    : INPUT choice$
    : LET choice = VAL(choice$)
    : LOOP
    : RETURN
    : '**** ASSIGN SEAT **********
    : assignseat:
    : PRINT " ASSIGN SEAT TO PASSENGER/CUSTOMER "
    : DO
    : GOSUB enterpsgrname
    : GOSUB searchseat
    : IF empty = 0 THEN GOSUB writedata
    : CLS
    : PRINT seatloc.a; CHR$(197); seatloc.b; CHR$(197); seatloc.C; CHR$(197); seatloc.d; CHR$(197); seatloc.e; CHR$(197); seatloc.f
    : LET C$ = INPUT$(1)
    : LOOP WHILE C$ <> CHR$(27)
    : RETURN
    :
    : '*********** DISPLAY SEAT AVALIABLE ********
    : displayavailableseat:
    : CLS
    :
    : LET recno = 0
    : DO WHILE recno <= 40
    : recno = recno + 1
    : GET #1, recno, seatloc
    : IF seatloc.a = "available" THEN
    : PRINT recno; "A", seatloc.a
    :
    : ELSEIF seatloc.b = "available" THEN
    : PRINT recno; "B", seatloc.b
    :
    : ELSEIF seatloc.C = "available" THEN
    : PRINT recno; "C", seatloc.C
    :
    : ELSEIF seatloc.d = "available" THEN
    : PRINT recno; "D", seatloc.d
    :
    : ELSEIF seatloc.e = "available" THEN
    : PRINT recno; "E", seatloc.e
    :
    : ELSEIF seatloc.f = "available" THEN
    : PRINT recno; "F", seatloc.f
    :
    : END IF
    : LOOP
    : RETURN
    : '*********** PASSENGERS WITH SEATS ********
    : displaypassengersseat:
    : LET recno = 0
    : DO WHILE NOT EOF(1)
    : recno = recno + 1
    : GET #1, recno, seatloc
    : IF seatloc.a <> "available" THEN PRINT recno; "A", seatloc.a
    : IF seatloc.b <> "available" THEN PRINT recno; "B", seatloc.b
    : IF seatloc.C <> "available" THEN PRINT recno; "C", seatloc.C
    : IF seatloc.d <> "available" THEN PRINT recno; "D", seatloc.d
    : IF seatloc.e <> "available" THEN PRINT recno; "E", seatloc.e
    : IF seatloc.f <> "available" THEN PRINT recno; "F", seatloc.f
    : LOOP
    : RETURN
    :
    : '******** INITIALIZE FILE *********
    : initializerecord:
    : CLS
    : PRINT "THIS WILL DELETE ALL RECORDS!"
    : PRINT : PRINT "DO YOU WANT TO PROCEED (y/n)"
    : INPUT "", C$
    : IF C$ = "y" OR C$ = "Y" THEN
    : LET recno = 0
    : DO WHILE recno <= 40
    : LET recno = recno + 1
    : GET #1, recno, seatloc
    : LET seatloc.a = "available"
    : LET seatloc.b = "available"
    : LET seatloc.C = "available"
    : LET seatloc.d = "available"
    : LET seatloc.e = "available"
    : LET seatloc.f = "available"
    : PUT #1, recno, seatloc
    : LOOP
    : ELSE
    : END IF
    : RETURN
    : '************* write data to file *************
    : writedata:
    : PUT #1, recno, seatloc
    : RETURN
    : '************ ENTER PASSENGERS NAME **********
    : enterpsgrname:
    : LOCATE , , 1 ' SET CURSOR TO VISIBLE
    : LINE INPUT "name of passenger"; psgrname$
    :
    :
    : RETURN
    : '************** search record **********
    : searchseat:
    : LET recno = 0 AND count = 0
    : DO WHILE [red]switch = 1[/red] OR count <= 40
    : recno = recno + 1: count = count + 1
    : GET #1, recno, seatloc
    : IF seatloc.a = "available" THEN
    : LET empty = 1 AND seatloc.a = psgrname$
    : ELSEIF seatloc.b = "available" THEN LET empty = 1 AND seatloc.b = psgrname$
    : ELSEIF seatloc.C = "available" THEN LET empty = 1 AND seatloc.C = psgrname$
    : ELSEIF seatloc.d = "available" THEN LET empty = 1 AND seatloc.d = psgrname$
    : ELSEIF seatloc.e = "available" THEN LET empty = 1 AND seatloc.e = psgrname$
    : ELSEIF seatloc.f = "available" THEN LET empty = 1 AND seatloc.f = psgrname$
    : END IF
    : LOOP
    :
    : displayall:
    : CLS
    : FOR i = 1 TO 40
    : GET #1, i, seatloc
    : PRINT USING format$; seatloc.a; seatloc.b; seatloc.C; seatloc.d; seatloc.e; seatloc.f
    : NEXT i
    : RETURN
    : '************* END SESSION **************
    : TERMINATE:
    : END
    : RETURN
    :
    : *************
    : well thats that.the system is a plane seat reservation system implementing random file management.it is supposed to help the user know wen a seat is occupied and where to fit a passenger.the plane as 40 rows with six seats in each row namjed A-F.
    :
    : thanks for whtever help u render .one more how do i use this heaven"s mailbos.
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    Try it without the SWITCH=1. SWITCH is useless. You don't use it anywhere.

    You can use Programmers Heaven mailbox like following:
    - if you want to send a letter just click on Mailbox, then click on Write Message. Type the name of the user you want to send a mail to, then type a subject and a text. Click on Send message to send, and Preview Message to preview the current letter.
    - you can check on the Inbox section if any letters arrived to you.
    - you can check on the Outbox section what you have sent since that moment you last checked it.

    Sorry for any english mistakes, my english is terrible...

    ****************
    Any questions? Just ask!

    :-) [b][blue]GAASHIUS[/blue][/b] :-)


  • mr_orchemr_orche Member Posts: 12
    : i have been working on a personal assignment.well my problem is my subroutine refuses to exit after execution.I use qb4.5 and another is i cant exit a loop wen i have set the conditions.below is the source code .pls correct me anywhere.(i probably have bad programming practice...)well
    : .
    : .
    : .
    : .' this program leeps record of occupied and available seats in an airline.
    : 'this is an airline reservation system.the file system implemented is RANDOM.
    : ' variables used
    : ' recNo% - records number for file
    : ' person$ - stores name of passengers
    : ' screen - helps control display of prints
    : ' record name is "SEATS"
    : ' problem def>.. the airplane as 40 rows with six seats labeled A to F for each row
    : ' the program allows various choices of action by the operator.
    : ' choices available are
    : ' 1.) assigning of seats to passengers
    : ' 2.) displayinhg of available seats
    : ' 3.) displaying of occupied seats.
    : ' 4.) initializing or reseting of record
    :
    : TYPE recordstructure
    : a AS STRING * 20
    : b AS STRING * 20
    : C AS STRING * 20
    : d AS STRING * 20
    : e AS STRING * 20
    : f AS STRING * 20
    : END TYPE
    : DIM seatloc AS recordstructure
    : CLS
    : OPEN "plane.dat" FOR RANDOM AS #1
    :
    : GOSUB initializeimages
    : PRINT TITLE$
    :
    : DO
    : GOSUB PRINTMENU
    : GOSUB INPUTCHOICE
    : ON choice GOSUB assignseat, displayavailableseat, displaypassengersseat, initializerecord, displayall, TERMINATE
    : LOOP WHILE INKEY$ <> CHR$(27)
    : END
    : '********** intilize images *******
    : initializeimages:
    : LET TITLE$ = " AIRLINE RESERVATION SYSTEM "
    : LET COLHEAD$ = "SEAT A SEAT B SEAT C SEAT D SEAT E SEAT F"
    : LET format$ = " "
    : RETURN
    : '************ MENUS ****************
    :
    : PRINTMENU:
    : PRINT
    : PRINT
    : PRINT " 1.) ASSIGN SEAT TO PASSENGER"
    : PRINT " 2.) DISPLAY AVAILABLE SEATS"
    : PRINT " 3.) DISPLAY PASSENGERS WITH SEAT"
    : PRINT " 4.) INITIALIZE IMAGES"
    : PRINT " 5.) PRINT ALL DATA"
    : PRINT " 6.) END APPLICATION"
    : PRINT
    : PRINT
    : PRINT " SELECT OPTION (1-5)";
    : RETURN
    :
    : '********** CHOICE **********
    : INPUTCHOICE:
    : DO WHILE choice < 1 OR choice > 5
    : INPUT choice$
    : LET choice = VAL(choice$)
    : LOOP
    : RETURN
    : '**** ASSIGN SEAT **********
    : assignseat:
    : PRINT " ASSIGN SEAT TO PASSENGER/CUSTOMER "
    : DO
    : GOSUB enterpsgrname
    : GOSUB searchseat
    : IF empty = 0 THEN GOSUB writedata
    : CLS
    : PRINT seatloc.a; CHR$(197); seatloc.b; CHR$(197); seatloc.C; CHR$(197); seatloc.d; CHR$(197); seatloc.e; CHR$(197); seatloc.f
    : LET C$ = INPUT$(1)
    : LOOP WHILE C$ <> CHR$(27)
    : RETURN
    :
    : '*********** DISPLAY SEAT AVALIABLE ********
    : displayavailableseat:
    : CLS
    :
    : LET recno = 0
    : DO WHILE recno <= 40
    : recno = recno + 1
    : GET #1, recno, seatloc
    : IF seatloc.a = "available" THEN
    : PRINT recno; "A", seatloc.a
    :
    : ELSEIF seatloc.b = "available" THEN
    : PRINT recno; "B", seatloc.b
    :
    : ELSEIF seatloc.C = "available" THEN
    : PRINT recno; "C", seatloc.C
    :
    : ELSEIF seatloc.d = "available" THEN
    : PRINT recno; "D", seatloc.d
    :
    : ELSEIF seatloc.e = "available" THEN
    : PRINT recno; "E", seatloc.e
    :
    : ELSEIF seatloc.f = "available" THEN
    : PRINT recno; "F", seatloc.f
    :
    : END IF
    : LOOP
    : RETURN
    : '*********** PASSENGERS WITH SEATS ********
    : displaypassengersseat:
    : LET recno = 0
    : DO WHILE NOT EOF(1)
    : recno = recno + 1
    : GET #1, recno, seatloc
    : IF seatloc.a <> "available" THEN PRINT recno; "A", seatloc.a
    : IF seatloc.b <> "available" THEN PRINT recno; "B", seatloc.b
    : IF seatloc.C <> "available" THEN PRINT recno; "C", seatloc.C
    : IF seatloc.d <> "available" THEN PRINT recno; "D", seatloc.d
    : IF seatloc.e <> "available" THEN PRINT recno; "E", seatloc.e
    : IF seatloc.f <> "available" THEN PRINT recno; "F", seatloc.f
    : LOOP
    : RETURN
    :
    : '******** INITIALIZE FILE *********
    : initializerecord:
    : CLS
    : PRINT "THIS WILL DELETE ALL RECORDS!"
    : PRINT : PRINT "DO YOU WANT TO PROCEED (y/n)"
    : INPUT "", C$
    : IF C$ = "y" OR C$ = "Y" THEN
    : LET recno = 0
    : DO WHILE recno <= 40
    : LET recno = recno + 1
    : GET #1, recno, seatloc
    : LET seatloc.a = "available"
    : LET seatloc.b = "available"
    : LET seatloc.C = "available"
    : LET seatloc.d = "available"
    : LET seatloc.e = "available"
    : LET seatloc.f = "available"
    : PUT #1, recno, seatloc
    : LOOP
    : ELSE
    : END IF
    : RETURN
    : '************* write data to file *************
    : writedata:
    : PUT #1, recno, seatloc
    : RETURN
    : '************ ENTER PASSENGERS NAME **********
    : enterpsgrname:
    : LOCATE , , 1 ' SET CURSOR TO VISIBLE
    : LINE INPUT "name of passenger"; psgrname$
    :
    :
    : RETURN
    : '************** search record **********
    : searchseat:
    : LET recno = 0 AND count = 0
    : DO WHILE switch = 1 OR count <= 40
    : recno = recno + 1: count = count + 1
    : GET #1, recno, seatloc
    : IF seatloc.a = "available" THEN
    : LET empty = 1 AND seatloc.a = psgrname$
    : ELSEIF seatloc.b = "available" THEN LET empty = 1 AND seatloc.b = psgrname$
    : ELSEIF seatloc.C = "available" THEN LET empty = 1 AND seatloc.C = psgrname$
    : ELSEIF seatloc.d = "available" THEN LET empty = 1 AND seatloc.d = psgrname$
    : ELSEIF seatloc.e = "available" THEN LET empty = 1 AND seatloc.e = psgrname$
    : ELSEIF seatloc.f = "available" THEN LET empty = 1 AND seatloc.f = psgrname$
    : END IF
    : LOOP
    :
    : displayall:
    : CLS
    : FOR i = 1 TO 40
    : GET #1, i, seatloc
    : PRINT USING format$; seatloc.a; seatloc.b; seatloc.C; seatloc.d; seatloc.e; seatloc.f
    : NEXT i
    : RETURN
    : '************* END SESSION **************
    : TERMINATE:
    : END
    : RETURN
    :
    : *************
    : well thats that.the system is a plane seat reservation system implementing random file management.it is supposed to help the user know wen a seat is occupied and where to fit a passenger.the plane as 40 rows with six seats in each row namjed A-F.
    :
    : thanks for whtever help u render .one more how do i use this heaven"s mailbos.
    :
    :
    :


    well, the problem is in INPUTCHOICE:
    : '********** CHOICE **********
    : INPUTCHOICE:
    : DO WHILE choice < 1 OR choice > 5 ;change this line!!!
    : INPUT choice$
    : LET choice = VAL(choice$)
    : LOOP
    : RETURN

    you must change these lines like this:
    '********** CHOICE **********
    INPUTCHOICE:
    DO WHILE choice >= 1 OR choice <= 5
    INPUT choice$
    LET choice = VAL(choice$)
    LOOP
    RETURN


    btw, now i use qb45, i want to have a newer version of qb, but i
    have no money, i'm a poor man, would you send me a copy of newer
    qb version, especially if it's a free version?
    mr_orche@hotmail.com
    thx
Sign In or Register to comment.