Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Working on a VERY simple database in QBasic... Need Some Help/Ideas

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
Here's what I'm building:

A program to assist in running the Cub Scout Pinewood Derby. I'm writing this in QBasic because the people who may be maintaining this program in the future need a free, easy programming module that does not require compilation to run.

Basically what I've done so far is write sub procedures to enter data, view data, edit data, and delete data. What I need now is a way to update these when a race is complete and offer a ranking system... and I'm drawing a blank... The code is posted below. Thanks in advance to everyone who helps...

-William Kenny
Programmer for KennySoft Solutions


Code:
DECLARE SUB DelData ()
DECLARE SUB AVG ()
DECLARE SUB RaceSetup ()
DECLARE SUB RaceStart ()
DECLARE SUB CheckNoRacers ()
DECLARE SUB EditDB ()
DECLARE SUB GetData ()
DECLARE SUB EnterData ()
ON ERROR GOTO ErrHndlr


SCREEN 11
TYPE TgrRecord
	LstNme  AS STRING * 10
	FstNme  AS STRING * 10
	CarNo   AS INTEGER
	CarOz   AS STRING * 3
	Lane1   AS SINGLE
	Lane2   AS SINGLE
	Lane3   AS SINGLE
	Lane4   AS SINGLE
	AVG     AS SINGLE
END TYPE

DIM SHARED Tiger AS TgrRecord




3
CLS
PRINT "Tiger Scout Pinewood Derby Setup"
PRINT ""
PRINT "1) Enter Data"
PRINT "2) Edit Data"
PRINT "3) Delete Data"
PRINT "4) View Data"
PRINT "5) View All Times"
PRINT "6) Update # Of Registered Cars"
PRINT "7) AVG Times"
PRINT "8) Exit"
PRINT ""
PRINT ""
INPUT "What option will you choose"; choice%
SELECT CASE choice%
CASE 1
CHAIN "u:\qbasic\pinewo~1\REGTIGER.BAS"
CASE 2
EditDB
CASE 3
DelData
CASE 4
GetData
CASE 5
RaceSetup
CASE 6
CheckNoRacers
CASE 7
AVG
CASE 8
END
CASE ELSE
GOTO 3
END SELECT
GOTO 3

ErrHndlr:
SELECT CASE ERR
	CASE 6
		GOTO 3
	CASE 75
		CLOSE
		RESUME NEXT
	CASE ELSE
		
END SELECT

SUB AVG
CHAIN "u:\qbasic\pinewo~1\autoavg"
END SUB

SUB CheckNoRacers
racers% = 0
OPEN "u:\qbasic\pinewo~1\TgrRecrd.qdb" FOR RANDOM AS #1 LEN = LEN(Tiger)




DO WHILE NOT EOF(1)
racers% = racers% + 1
GET 1, racers%, Tiger
IF Tiger.CarNo% > 0 THEN
LOCATE 11, 1: PRINT "There are currently"
	LOCATE 11, 20: PRINT Tiger.CarNo%
	SELECT CASE MenuRacers%
	CASE IS < 10
		LOCATE 11, 23
	CASE IS > 9
		LOCATE 11, 24
	CASE IS > 99
		LOCATE 11, 25
	END SELECT
PRINT &quot;cars registered&quot;



END IF
LOOP
CLOSE
'DO WHILE INKEY$ = &quot;&quot;
'LOOP
END SUB

SUB ChkLane
Chk% = 0
OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)

DO WHILE NOT EOF(1)
Chk% = Chk% + 1
GET 1, Chk%, Tiger
LOOP
Chk% = Chk% - 1
PRINT Chk%

DO WHILE INKEY$ = &quot;&quot;
LOOP
CLOSE
END SUB

SUB DelData

PRINT &quot;Which Car Number do you wish to delete?&quot;
OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
i% = 0
CLS
PRINT &quot; __________________________________________&quot;
PRINT &quot;|  LAST NAME  | FIRST NAME  | car# | weight|&quot;
PRINT &quot;|-------------|-------------|------|-------|&quot;
PRINT &quot;|             |             |      |       |&quot;
format$ = &quot;| \         \ | \         \ |  ##  |  \ \  |&quot;
DO WHILE NOT EOF(1)
	i% = i% + 1
	GET #1, i%, Tiger
     IF Tiger.CarNo% > 0 THEN
	PRINT USING format$; Tiger.LstNme$; Tiger.FstNme$; Tiger.CarNo%; Tiger.CarOz$
     END IF

     IF Tiger.CarNo% = 0 THEN
	PRINT &quot;| There are NO|entries in th|is dat|abase! |&quot;
	PRINT &quot;|_____________|_____________|______|_______|&quot;
	PRINT &quot;&quot;
	PRINT &quot;Press Any Key To Continue&quot;
	DO WHILE INKEY$ = &quot;&quot;
	LOOP
	CLOSE
	GOTO 10000
     END IF

LOOP
PRINT &quot;|_____________|_____________|______|_______|&quot;
CLOSE

OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
INPUT &quot;What Car Number would you like to delete? (0 = exit)&quot;; delete%
IF delete% = 0 THEN
	CLOSE
	GOTO 10000
END IF


Tiger.LstNme$ = &quot;&quot;
Tiger.FstNme$ = &quot;&quot;
Tiger.CarNo% = 0
Tiger.Lane1 = 0
Tiger.Lane2 = 0
Tiger.Lane3 = 0
Tiger.Lane4 = 0
Tiger.AVG = 0
PUT #1, delete%, Tiger

CLOSE

10000

END SUB

SUB EditDB
PRINT &quot;Which Car Number do you wish to edit?&quot;
OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
i% = 0
CLS
PRINT &quot; __________________________________________&quot;
PRINT &quot;|  LAST NAME  | FIRST NAME  | car# | weight|&quot;
PRINT &quot;|-------------|-------------|------|-------|&quot;
PRINT &quot;|             |             |      |       |&quot;
format$ = &quot;| \         \ | \         \ |  ##  |  \ \  |&quot;
DO WHILE NOT EOF(1)
	i% = i% + 1
	GET #1, i%, Tiger
     IF Tiger.CarNo% > 0 THEN
	PRINT USING format$; Tiger.LstNme$; Tiger.FstNme$; Tiger.CarNo%; Tiger.CarOz$
     END IF

     IF Tiger.CarNo% = 0 THEN
	PRINT &quot;| There are NO|entries in th|is dat|abase! |&quot;
	PRINT &quot;|_____________|_____________|______|_______|&quot;
	PRINT &quot;&quot;
	PRINT &quot;Press Any Key To Continue&quot;
	DO WHILE INKEY$ = &quot;&quot;
	LOOP
	GOTO 9999
     END IF

LOOP
PRINT &quot;|_____________|_____________|______|_______|&quot;
CLOSE

OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
INPUT &quot;What Car Number would you like to edit? (0 = exit)&quot;; edit%
IF edit% = 0 THEN
	CLOSE
	GOTO 9999
END IF
PRINT &quot;&quot;
PRINT &quot;&quot;
INPUT &quot;Last Name?       &quot;; Tiger.LstNme$
INPUT &quot;First Name?      &quot;; Tiger.FstNme$
Tiger.CarNo% = edit%
INPUT &quot;Weight (in oz.)  &quot;; Tiger.CarOz$
INPUT &quot;Lane 1 Time      &quot;; Tiger.Lane1
INPUT &quot;Lane 2 Time      &quot;; Tiger.Lane2
INPUT &quot;Lane 3 Time      &quot;; Tiger.Lane3
INPUT &quot;Lane 4 Time      &quot;; Tiger.Lane4
PUT #1, edit%, Tiger
AVG
9999
CLOSE

END SUB

SUB EnterData

1

OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)

recon% = 0
recno% = 0
DO WHILE NOT EOF(1)
recno% = recno% + 1
GET 1, recno%, Tiger
IF Tiger.CarNo% > 0 THEN
recon% = recno% + 1
END IF
LOOP






5
R% = recon%
CLS
INPUT &quot;Last Name   &quot;; Tiger.LstNme$
INPUT &quot;First Name  &quot;; Tiger.FstNme$
Tiger.CarNo% = R%
INPUT &quot;Weight (oz.)&quot;; Tiger.CarOz$
Tiger.Lane1 = 0
Tiger.Lane2 = 0
Tiger.Lane3 = 0
Tiger.Lane4 = 0
Tiger.AVG = 0
PUT 1, R%, Tiger
4
INPUT &quot;Enter another? (yes/no) &quot;; ynB$
SELECT CASE ynB$
CASE &quot;yes&quot;
R% = R% + 1
GOTO 5
CASE &quot;no&quot;
GOTO 2
CASE ELSE
GOTO 4
END SELECT


2
CLOSE

END SUB

SUB GetData

OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
i% = 0
CLS
PRINT &quot; _____________________________________________________&quot;
PRINT &quot;|  LAST NAME  | FIRST NAME  | car# | weight| avg time | &quot;
PRINT &quot;|-------------|-------------|------|-------|----------|&quot;
PRINT &quot;|             |             |      |       |          |&quot;
format$ = &quot;| \         \ | \         \ |  ##  |  \ \  |  ##.###  |&quot;
DO WHILE NOT EOF(1)
	i% = i% + 1
	GET #1, i%, Tiger
       
	SELECT CASE Tiger.CarNo%
	CASE IS > 0
	PRINT USING format$; Tiger.LstNme$; Tiger.FstNme$; Tiger.CarNo%; Tiger.CarOz$; Tiger.AVG
	CASE 0
	END SELECT
LOOP
PRINT &quot;|             |             |      |       |          |&quot;
PRINT &quot;|_____________|_____________|______|_______|__________|&quot;
CLOSE

PRINT &quot;Press Any Key To Continue&quot;



DO WHILE INKEY$ = &quot;&quot;
LOOP


END SUB

SUB RaceSetup
PRINT &quot;Race Setup&quot;


CLS
OPEN &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot; FOR RANDOM AS #1 LEN = LEN(Tiger)
format2$ = &quot;|  ##  |  ##.###  |  ##.###  |  ##.###  |  ##.###  |  ##.###  |&quot;
PRINT &quot; _____________________________________________________________&quot;
PRINT &quot;| car# | Lane 1   | Lane 2   | Lane 3   | Lane 4   | Avg Time |&quot;
PRINT &quot;|------|----------|----------|----------|----------|----------|&quot;
PRINT &quot;|      |          |          |          |          |          |&quot;
DO WHILE NOT EOF(1)
i% = i% + 1
GET 1, i%, Tiger

SELECT CASE Tiger.CarNo%
CASE IS > 0
PRINT USING format2$; Tiger.CarNo%; Tiger.Lane1; Tiger.Lane2; Tiger.Lane3; Tiger.Lane4; Tiger.AVG
CASE 0
END SELECT
LOOP
CLOSE
PRINT &quot;|      |          |          |          |          |          |&quot;
PRINT &quot;|______|__________|__________|__________|__________|__________|&quot;

PRINT &quot;&quot;
PRINT &quot;&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP
END SUB

SUB RaceStart
END SUB
 
KennySoft:

You should seriously compress the program. There are several redundencies that should be eliminated. Below is the revised code so that it'll run somewhat decent should someone else want to offer suggestions.

'---Start Copying here---
DECLARE SUB Avg ()
DECLARE SUB DelRacer ()
DECLARE SUB DispData (ddNumOfCars%)
DECLARE SUB EditRacer ()
DECLARE SUB EnterData ()
DECLARE SUB RaceSetup ()
DECLARE SUB RaceStart ()
DECLARE SUB CompressFile ()

'CONST DataFile$ = &quot;u:\qbasic\pinewo~1\TgrRecrd.qdb&quot;
'CONST TempFile$ = &quot;u:\qbasic\pinewo~1\Shrink.tmp&quot;
CONST DataFile$ = &quot;A:\TgrRecrd.qdb&quot;, TempFile$ = &quot;A:\Shrink.tmp&quot;

SCREEN 12
TYPE TgrRecord
LstNme AS STRING * 10
FstNme AS STRING * 10
CarNo AS INTEGER
CarOz AS STRING * 3
Lane1 AS SINGLE
Lane2 AS SINGLE
Lane3 AS SINGLE
Lane4 AS SINGLE
Avg AS SINGLE
END TYPE

DIM SHARED Tiger AS TgrRecord

MainMenu:
CLS
PRINT &quot;Tiger Scout Pinewood Derby Setup&quot;
PRINT &quot;&quot;
PRINT &quot;1) Enter Data&quot;
PRINT &quot;2) Edit Data&quot;
PRINT &quot;3) Delete Data&quot;
PRINT &quot;4) View Data&quot;
PRINT &quot;5) View All Times&quot;
PRINT &quot;6) AVG Times&quot;
PRINT
PRINT &quot;0) Exit&quot;
PRINT
PRINT
INPUT &quot;What option will you choose&quot;; choice%

SELECT CASE choice%
CASE 1
EnterData
CASE 2
EditRacer
CASE 3
DelRacer
CASE 4
DispData (0)
PRINT &quot;Press Any Key To Continue&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP
CASE 5
RaceSetup
CASE 6
Avg
CASE 0
SCREEN 0
END
END SELECT
GOTO MainMenu

'
'
SUB Avg
CHAIN &quot;u:\qbasic\pinewo~1\autoavg&quot;
END SUB

'
'
SUB ChkLane
OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
DO WHILE NOT EOF(1)
Chk% = Chk% + 1
GET 1, Chk%, Tiger
LOOP
Chk% = Chk% - 1
PRINT Chk%
DO WHILE INKEY$ = &quot;&quot;
LOOP
CLOSE
END SUB

'
'
SUB CompressFile

OPEN DataFile$ FOR RANDOM AS #11 LEN = LEN(Tiger)
OPEN TempFile$ FOR RANDOM AS #10 LEN = LEN(Tiger)
OrgNumRacers = LOF(11) / LEN(Tiger)
PRINT
PRINT &quot;There are currently&quot;; STR$(OrgNumRacers); &quot; car(s) recorded.&quot;
FOR Cycle = 1 TO OrgNumRacers
GET #11, , Tiger
IF EOF(11) THEN EXIT FOR
IF RTRIM$(Tiger.LstNme$) <> &quot;(erased)&quot; THEN
SavedCounter = SavedCounter + 1
Tiger.CarNo = SavedCounter
PUT #10, , Tiger
ELSE
DelCounter = DelCounter + 1
END IF
NEXT
CLOSE
PRINT
PRINT &quot;Records marked for deletion: &quot;; STR$(DelCounter)
KILL DataFile$
PRINT &quot;Records saved & resequenced: &quot;; STR$(SavedCounter)
NAME TempFile$ AS DataFile$
PRINT
CLS
DispData (0)
PRINT &quot;Press any key to continue&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP

END SUB

'
'
SUB DelRacer
DispData DelRecNo%
IF DelRecNo% = 0 THEN
'Nothing in database
PRINT &quot;Press Any Key To Continue&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP
EXIT SUB
END IF
OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
INPUT &quot;What Car Number would you like to delete? (0 = exit)&quot;; DelRecNo%
IF DelRecNo% THEN
Tiger.LstNme$ = &quot;(erased)&quot;
PUT #1, DelRecNo%, Tiger
END IF
CLOSE
CompressFile
END SUB

'
'
SUB DispData (ddNumOfCars%)

OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
ddNumOfCars% = LOF(1) / LEN(Tiger)
CLS
PRINT &quot; _____________________________________________________&quot;
PRINT &quot;| LAST NAME | FIRST NAME | car# | weight| avg time | &quot;
PRINT &quot;|-------------|-------------|------|-------|----------|&quot;
PRINT &quot;| | | | | |&quot;
IF ddNumOfCars% THEN
FOR i% = 1 TO ddNumOfCars%
format$ = &quot;| \ \ | \ \ | ## | \ \ | ##.### |&quot;
GET #1, i%, Tiger
PRINT USING format$; Tiger.LstNme$; Tiger.FstNme$; Tiger.CarNo%; Tiger.CarOz$; Tiger.Avg
NEXT i%
ELSE
PRINT &quot;| There are NO registered cars on record.| Please |&quot;
PRINT &quot;| re-enter required information by selecting #1 from |&quot;
PRINT &quot;| | the MAIN|MENU! | | |&quot;
END IF
PRINT &quot;| | | | | |&quot;
PRINT &quot;|_____________|_____________|______|_______|__________|&quot;
PRINT
CLOSE

END SUB

'
'
SUB EditRacer

DispData EditRecNo%
IF EditRecNo% = 0 THEN
'Nothing in database
PRINT &quot;Press Any Key To Continue&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP
EXIT SUB
END IF
OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
INPUT &quot;What Car Number would you like to edit? (0 = exit)&quot;; EditRecNo%
IF EditRecNo% THEN
Tiger.CarNo% = EditRecNo%
PRINT
PRINT
INPUT &quot;Last Name? &quot;; Tiger.LstNme$
INPUT &quot;First Name? &quot;; Tiger.FstNme$
INPUT &quot;Weight (in oz.) &quot;; Tiger.CarOz$
INPUT &quot;Lane 1 Time &quot;; Tiger.Lane1
INPUT &quot;Lane 2 Time &quot;; Tiger.Lane2
INPUT &quot;Lane 3 Time &quot;; Tiger.Lane3
INPUT &quot;Lane 4 Time &quot;; Tiger.Lane4
PUT #1, EditRecNo%, Tiger
Avg
END IF
CLOSE

END SUB

'
'
SUB EnterData

CLS
OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
RecNo% = LOF(1) / LEN(Tiger)
AddNewRacer:
IF RecNo% THEN
RecNo% = RecNo% + 1
ELSE
RecNo% = 1
END IF
PRINT
INPUT &quot;Last Name &quot;; Tiger.LstNme$
INPUT &quot;First Name &quot;; Tiger.FstNme$
Tiger.CarNo% = RecNo%
INPUT &quot;Weight (oz.)&quot;; Tiger.CarOz$
PUT 1, RecNo%, Tiger
INPUT &quot;Enter another? (yes/no) &quot;; yn$
IF LEFT$(LTRIM$(LCASE$(yn$)), 1) = &quot;y&quot; THEN GOTO AddNewRacer
CLOSE

END SUB

'
'
SUB RaceSetup

PRINT &quot;Race Setup&quot;
CLS
OPEN DataFile$ FOR RANDOM AS #1 LEN = LEN(Tiger)
format2$ = &quot;| ## | ##.### | ##.### | ##.### | ##.### | ##.### |&quot;
PRINT &quot; _____________________________________________________________&quot;
PRINT &quot;| car# | Lane 1 | Lane 2 | Lane 3 | Lane 4 | Avg Time |&quot;
PRINT &quot;|------|----------|----------|----------|----------|----------|&quot;
PRINT &quot;| | | | | | |&quot;
DO WHILE NOT EOF(1)
i% = i% + 1
GET 1, i%, Tiger
SELECT CASE Tiger.CarNo%
CASE IS > 0
PRINT USING format2$; Tiger.CarNo%; Tiger.Lane1; Tiger.Lane2; Tiger.Lane3; Tiger.Lane4; Tiger.Avg
CASE 0
END SELECT
LOOP
CLOSE
PRINT &quot;| | | | | | |&quot;
PRINT &quot;|______|__________|__________|__________|__________|__________|&quot;
PRINT &quot;&quot;
PRINT &quot;&quot;
DO WHILE INKEY$ = &quot;&quot;
LOOP

END SUB

'
'
SUB RaceStart
END SUB

'---End Copying here---

As far as your question: &quot;What I need now is a way to update these when a race is complete and offer a ranking system... and I'm drawing a blank... &quot;

You can setup the EditRacer to require a parameter so that it will know whether or not it is to edit the &quot;Racer&quot; automatically or by user.

Enjoy,
MiggyD &quot;The world shrinks more and more with every new user online.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top