' Program 9.6 ' Inventory and Retrieval and Update ' ' This program displays or updates records in a simulated-indexed file. ' The data for the simulated-indexed file is located in the random file ' INVDATA.DAT. The records in the random file are accessed by a key ' (stock number) that is entered by the user. Records may be displayed, ' added to the file, deleted from the file, or changed. ' ' ******************************************************************** ' * Main Module * ' ******************************************************************** COLOR 4, 7 GOSUB Initialization GOSUB Process.Inquiries.And.Updates GOSUB Wrap.Up END' ******************************************************************** ' * Initialization * ' ******************************************************************** Initialization: CLS ' Clear Screen ' ******** Define Record Structure ******** TYPE InventoryStructure Stock AS STRING * 4 Desc AS STRING * 15 Price AS SINGLE Quantity AS SINGLE END TYPE ' ******** Declare Record Variable ******** DIM Inventory AS InventoryStructure ' ************* Open Files **************** OPEN "a:INDEX1.dat" FOR INPUT AS #1 OPEN "a:DATA1.dat" FOR RANDOM AS #2 LEN = LEN(Inventory) ' ***** Declare and Load Array Index$ ***** DIM Index$(1 TO 100) FOR Record.Number% = 1 TO 100 INPUT #1, Index$(Record.Number%) ' Read Stock Numbers into Array NEXT Record.Number% CLOSE #1 RETURN
' ******************************************************************** ' * Process Inquiries and Updates * ' ******************************************************************** Process.Inquiries.And.Updates: CLS GOSUB Display.Menu GOSUB Accept.Code DO WHILE Code% <> 5 SELECT CASE Code% CASE 1 GOSUB Display.Record CASE 2 GOSUB Add.Record CASE 3 GOSUB Change.Record CASE 4 GOSUB Delete.Record END SELECT GOSUB Display.Menu GOSUB Accept.Code LOOP RETURN
' ******************************************************************** ' * Display Menu * ' ******************************************************************** Display.Menu: CLS COLOR 4 LOCATE 2, 19: PRINT "Menu for Inventory Retrieval And Update" LOCATE 3, 19: PRINT "---------------------------------------" COLOR 4 LOCATE 5, 19: PRINT " Code Function" LOCATE 6, 19: PRINT " ---- --------" COLOR 0 LOCATE 7, 19: PRINT " 1 Display Record" LOCATE 9, 19: PRINT " 2 Add Record" LOCATE 11, 19: PRINT " 3 Change Record" LOCATE 13, 19: PRINT " 4 Delete Record" LOCATE 15, 19: PRINT " 5 End Program" RETURN
' ******************************************************************** ' * Accept Code and Stock Number * ' ******************************************************************** Accept.Code: DO Switch$ = "ON" LOCATE 17, 52: PRINT SPC(10); COLOR 4 LOCATE 17, 19: INPUT "Enter a Code 1 through 5 ======> ", Code% DO WHILE Code% < 1 OR Code% > 5 BEEP: BEEP: BEEP: BEEP COLOR 31, 4 LOCATE 18, 19: PRINT "Code out of range, please reenter" COLOR 4, 7 LOCATE 17, 52: PRINT SPC(10); LOCATE 17, 52: INPUT "", Code% LOCATE 18, 19: PRINT SPC(40); LOOP RETURN
find.option: CLS LOCATE 2, 19 COLOR 4, 7 INPUT "Find by Part Code (P) or Record Number (R): ", find.by$ IF UCASE$(find.by$) = "P" THEN LOCATE 5, 19 COLOR 0, 7 INPUT "Stock Number ==================> ", Stock.Number$ GOSUB Validate.Stock.Number RETURN ELSE LOCATE 5, 19 COLOR 0, 7 INPUT "Record Number =================> ", Record.Number% RETURN END IF LOOP UNTIL Switch$ = "ON" CLS
' ******************************************************************** ' * Determine If Stock Number Is Valid * ' ******************************************************************** Validate.Stock.Number: Record.Number% = 0 FOR I% = 1 TO 100 IF Stock.Number$ = Index$(I%) THEN IF Code% = 2 THEN GOSUB Stock.Number.Error.Routine ELSE Record.Number% = I% EXIT FOR END IF END IF NEXT I% IF Record.Number% = 0 AND Code% <> 2 THEN GOSUB Stock.Number.Error.Routine END IF RETURN
' ******************************************************************** ' * Stock Number Error Routine * ' ******************************************************************** Stock.Number.Error.Routine: BEEP: BEEP: BEEP: BEEP IF Code% = 2 THEN LOCATE 20, 19 PRINT "Stock Number Already Exists" ELSE LOCATE 20, 19: PRINT "Stock Number Is Invalid" END IF LOCATE 22, 19 PRINT "Press any key to re-enter Code and Stock Number..." A$ = INPUT$(1) LOCATE 17, 52: PRINT SPC(10); LOCATE 19, 52: PRINT SPC(10); LOCATE 20, 19: PRINT SPC(50); LOCATE 22, 19: PRINT SPC(50); Switch$ = "OFF"
' ******************************************************************** ' * Display Record * ' ******************************************************************** Display.Record: GOSUB find.option CLS GET #2, Record.Number%, Inventory LOCATE 2, 25 COLOR 4, 7 PRINT "Displaying Record "; Inventory.Stock LOCATE 5, 20 COLOR 0, 7 PRINT "Stock Number =============> "; Inventory.Stock LOCATE 7, 20 PRINT "Description ==============> "; Inventory.Desc LOCATE 9, 20 PRINT USING "Selling Price ============>###.##"; Inventory.Price LOCATE 11, 20 PRINT USING "Quantity on Hand =========>###"; Inventory.Quantity IF Inventory.Quantity < 10 THEN LOCATE 12, 25 COLOR 31, 4 PRINT "WARNING - LOW QUANTITY" ELSE END IF COLOR 4, 7 PRINT : PRINT "Press any key to continue..." A$ = INPUT$(1) RETURN
' ******************************************************************** ' * Add Record * ' ******************************************************************** Add.Record: CLS INPUT "Stock Number =============> "; Stock.Number$ Record.Number% = 0 FOR I% = 1 TO 100 ' Search for "Empty" element in array Index$ IF Index$(I%) = "Empty" THEN Record.Number% = I% EXIT FOR END IF NEXT I% IF Record.Number% <> 0 THEN Inventory.Stock = Stock.Number$ GOSUB Request.Remaining.Data.Items ELSE PRINT PRINT "** ERROR ** Index is full" PRINT : PRINT "Press any key to continue..." A$ = INPUT$(1) END IF RETURN
' ******************************************************************** ' * Request Remaining Data Items * ' ******************************************************************** Request.Remaining.Data.Items: PRINT : INPUT "Description ==============> ", Inventory.Desc PRINT : INPUT "Selling Price ============> ", Inventory.Price PRINT : INPUT "Quantity on Hand =========> ", Inventory.Quantity PRINT : INPUT "Enter Y to add record, else N... ", Control$ Inventory.Stock = Stock.Number$ IF UCASE$(Control$) = "Y" THEN GOSUB Set.Index.And.Write.Record END IF RETURN
' ******************************************************************** ' * Set Index Array and Write Record * ' ******************************************************************** Set.Index.And.Write.Record: Index$(Record.Number%) = Stock.Number$ PUT #2, Record.Number%, Inventory RETURN
' ******************************************************************** ' * Change Record * ' ******************************************************************** Change.Record: GOSUB find.option GET #2, Record.Number%, Inventory PRINT : PRINT "Stock Number =============> "; Stock.Number$ PRINT PRINT "**** Enter a -1 if you do not want to change a data item ****" PRINT : INPUT "Description ==============> ", T.Desc$ IF T.Desc$ <> "-1" THEN Inventory.Desc = T.Desc$ END IF PRINT : INPUT "Selling Price ============> ", T.Price IF T.Price <> -1 THEN Inventory.Price = T.Price END IF PRINT : INPUT "Quantity on Hand =========> ", T.Quantity IF T.Quantity <> -1 THEN Inventory.Quantity = T.Quantity END IF PRINT : INPUT "Enter Y to update record, else N... ", Control$ IF UCASE$(Control$) = "Y" THEN PUT #2, Record.Number%, Inventory END IF RETURN
' ******************************************************************** ' * Delete Record * ' ******************************************************************** Delete.Record: GOSUB find.option PRINT COLOR 31, 4 PRINT "Are you sure you want to delete stock number "; Stock.Number$ COLOR 4, 7 PRINT : INPUT "Enter Y to delete record, else N... ", Control$ IF UCASE$(Control$) = "Y" THEN Index$(Record.Number%) = "Empty" END IF RETURN
' ******************************************************************** ' * Wrap-Up * ' ******************************************************************** Wrap.Up: CLS CLOSE OPEN "INDEX1.DAT" FOR OUTPUT AS #1 FOR Record.Number% = 1 TO 100 ' Write New Index to INVINDEX.DAT WRITE #1, Index$(Record.Number%) NEXT Record.Number% CLOSE PRINT "Inventory Retrieval and Update Program Terminated" PRINT : PRINT "Job Complete" RETURN
' ************************* End of Program ***************************
My Final Exam Code
Page 1 of 13 Replies - 2498 Views - Last Post: 29 May 2002 - 07:12 AM
#1
My Final Exam Code
Posted 30 July 2001 - 02:20 PM
Ok, everything on this works, cept the stupid Record.Number% isn't incrementing like it should... I've tried an incrementer and I'm sure it's just something stupid I'm overlooking, but a second opinion would be nice.
Replies To: My Final Exam Code
#3
Re: My Final Exam Code
Posted 30 July 2001 - 10:02 PM
BASIC is such a nasty language it is way to hard to follow. I remember when i used to program in it. It was fun but i would never of done any major projects.
:no:Oh and sorry i don't know qbasic. only know what was on the old TRS-80.
Sorry!
#4
Re: My Final Exam Code
Posted 29 May 2002 - 07:12 AM
The only part of the code I looked is "Determine is Stock Number is Valid" because this is where you said you got the error.
Since you determine that "Record.Number% = 0" I think that is why it won't increment. You state that the % of it will be 0 therefore it won't increment. I don't think you even need that bit of code. It looks correct without it. Instead take it out where it says "Record.Number% = 0" and leave it alone when it is further down and it says "Record.Number% = I%.
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote





|