' ' ' Structured Programming Example ' ' By ' ' David Tordrup of The QBasic Team ' ' Copyright (C) 1997 ' ' ' ' This code is very basic but functional. It could be improved in many ' ways, but as it only serves as an example of structured programming, ' the optimizing has been left out. You may however do to it whatever ' you like, use it in your own programs, whatever you see fit. ' ' This program was written in 6 minutes and debugged in 1 step. ' ' The pseudo code for our DataBase program: ' '{ Initialize Datatype } '{ Allocate memory for records } '{ Open random access file for read/write } ' ' Option 'Browse Records/Enter new record' ' ' Procedure 'Browse Records' ' { Get records from file } ' { Display records } ' end procedure ' ' Procedure 'Enter new record' ' { Get input for new record } ' { Append record to file } ' end procedure ' '{ End program } ' 'And the QBasic program: TYPE RecordType Names AS STRING * 25 Address AS STRING * 25 City AS STRING * 25 PhoneNr AS STRING * 10 END TYPE DIM Record AS RecordType OPEN "\RECORDS.DAT" FOR RANDOM AS #1 LEN = LEN(Record) DO CLS INPUT "(N)ew / (D)isplay records / (Q)uit?", VD$ SELECT CASE VD$ ' Routines for viewing/displaying CASE "N", "n" CLS INPUT "Name: ", Record.Names INPUT "Address: ", Record.Address INPUT "City/State:", Record.City INPUT "Telephone: ", Record.PhoneNr PUT #1, LOF(1) / LEN(Record) + 1, Record CASE "D", "d" FOR a% = 1 TO LOF(1) / LEN(Record) GET #1, a%, Record PRINT Record.Names PRINT Record.Address PRINT Record.City PRINT Record.PhoneNr NEXT a% SLEEP CASE "Q", "q" Done% = 1 CASE ELSE END SELECT LOOP UNTIL Done%