home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Overload
/
ShartewareOverload.cdr
/
database
/
dbsteel3.zip
/
SORTINT.BAS
< prev
next >
Wrap
BASIC Source File
|
1991-01-21
|
12KB
|
437 lines
3 ON ERROR GOTO 64200
4 DEFINT K,F,T,L,R,N
5 DIM K$(55)
6 DIM FLDN$(1,60),FTY(1,60),FL(1,60)
7 DEFINT X,P
8 DIM X(10000),T(10000),NREC(17),FD(3),Z$(60),L(100),R(100),F$(17)
10 MAXR= 6
12 GOSUB 8000
15 GOSUB 13000
16 H = A
17 GOSUB 7000
19 DEFSTR Z
20 A = H
25 GOSUB 9000
30 FLG = 0
45 L = 0
50 FOR T = 1 TO NREC(A)
55 L = L + FL(A,T)
60 NEXT T
70 DEFINT T
90 GOSUB 11000
100 GOSUB 10000
400 REM ****** GET DATA FROM DISKS *******
405 GOSUB 16000
420 FOR T = 1 TO 30000
429 IF T > MRN GOTO 26000
430 GET #1,T
433 REM
435 N = FD(1)
436 IF FTY(1,N) = 1 GOTO 500
438 IF T1 = 1 THEN X(T) = 0
439 X(T) = X(T)*1E+06
440 ON FTY(1,N) GOTO 500,550,600,650,650
500 REM *** LET X(T) = Z$(N)
510 GOTO 700
550 X(T) = CVI(Z$(N)) + X(T)
560 GOTO 700
600 X(T) = CVS(Z$(N)) + X(T)
610 GOTO 700
650 X(T) = CVD(Z$(N)) + X(T)
700 REM
705 T(T) = T
710 NEXT T
1200 LP = 1
1210 FLG = 0
2000 REM
2010 M = 5000
2020 GOSUB 30000
2110 GOSUB 2200
2120 GOSUB 30000
2130 GOTO 3000
2200 REM
2210 L(1) = 1
2220 R(1) = MAXR
2230 S = 1
2240 IF (L(S)) < R(S) THEN 2270
2250 S = S - 1
2260 GOTO 2640
2270 I = L(S)
2280 J = R(S)
2290 P1= X(J)
2300 M = (I + J)/2
2310 IF (J - I<6) THEN 2400
2320 IF ((P1>X(I)) AND (P1<X(M))) THEN 2400
2330 IF ((P1<X(I)) AND (P1>X(M))) THEN 2400
2340 IF ((X(I)<X(M)) AND (X(I)>P1)) THEN 2380
2350 IF ((X(I)>X(M)) AND (X(I)<P1)) THEN 2380
2360 SWAP X(M),X(J)
2365 SWAP T(M),T(J)
2370 GOTO 2390
2380 SWAP X(I),X(J)
2385 SWAP T(I),T(J)
2390 P1 = X(J)
2400 WHILE (I<J)
2410 WHILE (X(I)< P1)
2420 I = I + 1
2430 WEND
2440 J=J-1
2450 WHILE (I<J)AND(P1<X(J))
2460 J = J-1
2470 WEND
2480 IF (I>=J) THEN 2510
2490 SWAP X(I),X(J)
2500 SWAP T(I),T(J)
2510 WEND
2520 J = R(S)
2530 SWAP X(I),X(J)
2540 SWAP T(I),T(J)
2550 IF (I - L(S)>=R(S)-I) THEN 2600
2560 L(S + 1) = L(S)
2570 R(S + 1) = I - 1
2580 L(S) = I + 1
2590 GOTO 2630
2600 L(S + 1) = I + 1
2610 R(S + 1) = R(S)
2620 R(S) = I - 1
2630 S = S + 1
2640 IF (S > 0) THEN 2240
2650 RETURN
3000 REM ******** PUT IN FILE ************
3100 GOSUB 9100
3110 Q$ = "B:"+F$(A)
3200 GOSUB 9200
3300 FOR Q = 1 TO MAXR
3310 RN = T(Q)
3312 GET #1,RN
3330 LSET Z1$ = Y$
3340 PUT #2,Q
3350 NEXT Q
3500 CLOSE
3600 GOSUB 15000
3620 PRINT "SORT FINISHED "
3630 END
7000 GOSUB 12000
7005 OPEN "I",#1,"FFILE"
7010 INPUT #1,MAXF
7020 FOR A = 1 TO MAXF
7030 INPUT #1,A,F$(A),NREC(A),L(A)
7040 FOR N = 1 TO NREC(A)
7050 INPUT #1,FLDN$(1,N),FTY(1,N),FL(1,N)
7055 IF FTY(1,N) = 2 THEN INPUT #1,KY,KEYLIST
7060 NEXT N
7065 IF A = AHLD THEN RETURN
7070 NEXT A
7080 CLOSE #1
7100 RETURN
8000 GOSUB 12000
8005 OPEN "I",#1,"FFILE"
8010 INPUT #1,MAXF
8020 FOR A = 1 TO MAXF
8030 INPUT #1,A,F$(A),NREC(A),L(A)
8040 FOR N = 1 TO NREC(A)
8050 INPUT #1,FLDN$(1,N),FTY(1,N),FL(1,N)
8055 IF FTY(1,N) = 2 THEN INPUT #1,KY,KEYLIST
8060 NEXT N
8070 NEXT A
8080 CLOSE #1
8100 RETURN
9000 REM ******* OPEN FILE SUBROUTINE *******
9010 CLOSE #1
9020 OPEN "R",#1,F$(A),L(A)
9030 D = 0
9040 FOR T = 1 TO NREC(A)
9050 FIELD #1,D AS D$,FL(1,T) AS Z$(T)
9060 D = D + FL(1,T)
9070 NEXT T
9080 RETURN
9100 REM ******* OPEN FILE SUBROUTINE *******
9110 CLOSE #1
9120 OPEN "R",#1,F$(A),L
9140 PRINT " L(A) ";L
9150 FIELD #1,L AS Y$
9180 RETURN
9200 REM ******* OPEN FILE SUBROUTINE *******
9210 CLOSE #2
9220 OPEN "R",#2,Q$,L
9250 FIELD #2,L AS Z1$
9280 RETURN
10000 REM ******* INITAL SELECTION ********
10010 GOSUB 15000
10100 PRINT "************** SORT FILE PROGRAM **************"
10105 PRINT "FILE NUMBER = ";A;" FILE NAME = ";F$(A)
10110 PRINT ""
10120 FOR T = 1 TO NREC(A)
10130 PRINT T;"- ";FLDN$(A,T)
10140 NEXT T
10150 PRINT ""
10200 PRINT "*** WHICH FIELD IS THE PRIMARY SORT FIELD ? ***"
10210 GOSUB 60000
10212 IF DT#<1 OR DT#>NREC(A) GOTO 10210
10213 IF FTY(1,DT#) <> 2 THEN GOTO 10210
10215 T3 = FD(1)
10218 FD(1) = DT#
10219 T3 = DT#
10220 GOTO 10275
10230 PRINT "*********** WHICH FIELD IS THE SECONDARY FIELD ? **********"
10232 PRINT "- If the primary values are equal"
10234 PRINT "the record with the lowest secondary value will be stored first "
10240 GOSUB 60000
10242 IF DT#<1 OR DT#>NREC(A) GOTO 10240
10244 IF FTY(1,DT#) = 1 GOTO 10410
10246 FD(2) = DT#
10250 IF KTH= 2 GOTO 10275
10260 PRINT "************ WHICH FIELD IS THE THIRD FIELD ? *************"
10262 PRINT "- If both the primary value and the secondary value are equal"
10264 PRINT "the record with the lowest third value will be stored first"
10270 GOSUB 60000
10272 IF DT#<1 OR DT#>NREC(A) GOTO 10270
10273 IF FTY(1,DT#) = 1 GOTO 10410
10274 FD(3) = DT#
10275 ON FTY(1,T3) GOSUB 10400,10600,10500,10500,10500
10280 RETURN
10400 REM ***DEFSTR X,P
10410 IF KTH> 1 THEN PRINT "******** STRING VARIABLES MAY ONLY BE SORTED BY ONE FIELD ********"
10420 IF KTH> 1 GOTO 10100
10430 REM ***DIM X(4200),T(4200)
10490 RETURN
10500 REM *****DEFDBL X,P
10505 REM *****DIM X(4200),T(4200)
10510 RETURN
10600 IF KTH> 1 GOTO 10500
10610 REM ***DEFINT X,P
10620 REM ***DIM X(10000),T(10000)
10630 RETURN
11000 REM ******* INTRODUCTION ********
11100 GOSUB 15000
11110 PRINT "************************ SORT PROGRAM *************************"
11120 PRINT ""
11130 PRINT "FILE NUMBER : ";A;" FILE NAME : ";F$(A)
11140 PRINT ""
11200 PRINT ""
11210 PRINT "Up to 10000 records may be sorted on ONE INTEGER FIELD "
11220 PRINT "Up to 4200 records may be sorted on ONE ALFANUMRIC FIELDS "
11230 PRINT "Up to 4200 records may be sorted on THREE DIFFERENT NUMERIC FIELDS"
11300 PRINT ""
11310 PRINT "The sort program reads the file on the default disk drive, sorts"
11320 PRINT "the records, then writes a sorted file with the same file name"
11330 PRINT "on a disk drive B. "
11940 PRINT ""
11950 PRINT "****************** PRESS ANY KEY TO CONTINUE ******************"
11960 IF INKEY$ = "" GOTO 11960
11970 RETURN
12000 REM *****
12005 GOSUB 15000
12010 PRINT " PUT THE PROGRAM DATA DISK IN THE DEFAULT DISK DRIVE "
12020 PRINT ""
12030 PRINT " PRESS ANY KEY TO CONTINUE "
12040 IF INKEY$ = "" GOTO 12040
12050 RETURN
13000 REM *****
13100 GOSUB 15000
13110 PRINT "****************** SORT PROGRAM *******************"
13120 PRINT ""
13130 PRINT "********** WHICH FILE DO YOU WANT TO SORT *********"
13140 FOR T = 1 TO MAXF
13150 PRINT T;" - ";F$(T)
13160 NEXT T
13170 PRINT "***** ENTER THE FILE NUMBER THEN PRESS RETURN ******"
13180 GOSUB 60000
13185 IF DT#<1 OR DT# >MAXF GOTO 13180
13190 A = DT#
13195 AHLD = A
13200 RETURN
14000 REM ***** SORT SELECTION
14100 GOSUB 15000
14110 PRINT "******************* SORT PROGRAM ********************"
14120 PRINT ""
14130 PRINT "DO YOU WANT TO SORT A FILE ON :"
14140 PRINT ""
14150 PRINT " 1. ONLY ONE INTEGER FIELD"
14160 PRINT ""
14170 PRINT " 2. ONE TO THREE NUMERIC FIELDS "
14180 PRINT ""
14190 PRINT " 3. A STRING FIELD"
14200 PRINT ""
14300 PRINT "******* ENTER THE NUMBER THEN PRESS RETURN ********"
14400 GOSUB 60000
14410 T = DT#
14420 ON T GOTO 14500,14700,14900
14500 REM
14520 GOSUB 12000
14540 RUN "SORTINT"
14700 GOTO 10
14900 REM
14920 GOSUB 12000
14940 RUN "SORTSTR"
15000 REM CLEAR SCREEN
15010 CALL CSCREEN
15020 RETURN
16000 REM ****** FIND MAX RECORD
16100 MRN = LOF(1)/L(A)
16200 RETURN
26000 REM ******* ON ERROR ROUTINE ************
26200 PRINT "END OF FILE"
26205 MAXR = T - 1
26206 PRINT MAXR," MAX RECORD "
26210 GOTO 1200
30000 FOR T = 1 TO MAXR
31000 PRINT X(T)
32000 NEXT T
33000 RETURN
60000 REM ******* INTEGER LESS THEN 100 CHECK ********
60010 MAX = 2
60020 ACT$ = "1234567890"
60030 PRINT ">__<";
60040 GOTO 60200
60050 REM ******* INTEGER *******
60060 MAX = 8
60070 ACT$ = "1234567890-+,"
60080 PRINT ">________<";
60090 GOTO 60200
60100 REM ******* SINGLE PRECISION *******
60110 MAX = 10
60120 ACT$ = "1234567890+-,.%$"
60130 PRINT ">__________<";
60140 GOTO 60200
60150 REM ********* DOUBLE PRECISION
60160 MAX = 20
60170 ACT$ = "1234567890+-,.%$"
60180 PRINT ">____________________<";
60190 GOTO 60200
60200 REM ********** NUMBER CHECK **********
60210 A$ = ""
60220 K$(20) = " "
60230 KTMAX = 0
60240 FOR T9 = 1 TO MAX
60250 K$(T9) = " "
60260 NEXT T9
60270 DIG$ = "1234567890."
60280 DOTFLG = 0
60290 T2 = MAX + 1
60300 FOR T6 = 1 TO T2
60310 PRINT CHR$(8);
60320 NEXT T6
60330 IF INKEY$ = "" GOTO 60340 ELSE GOTO 60330
60340 KT = 0
60350 REM *********** CHECK ALFANUMERIC INPUT FOR LENGTH ***********
60360 KT = KT + 1
60370 REM
60380 W$ = INKEY$
60390 IF W$ = "" GOTO 60380
60400 C = ASC(W$)
60410 IF C = 0 THEN GOSUB 61900
60420 IF C = 13 GOTO 60540
60430 IF C = 17 GOTO 61130
60440 IF C = 19 GOTO 60670
60450 IF C = 4 GOTO 60720
60460 IF C = 6 GOTO 60780
60470 IF C = 1 GOTO 60950
60480 IF KT > MAX GOTO 60370
60490 IF INSTR(ACT$,W$) = 0 GOTO 61210
60500 K$(KT) = W$
60510 PRINT K$(KT);
60520 IF KT > KTMAX THEN KTMAX = KT
60530 GOTO 60360
60540 REM ********** RETURN **********
60550 FOR T9 = 1 TO KTMAX
60560 A$ = A$ + K$(T9)
60610 NEXT T9
60620 IF KTMAX = 0 THEN PRINT "1"
60630 IF KTMAX = 0 THEN DT# = 1
60640 IF KTMAX = 0 THEN RETURN
60650 PRINT ""
60660 GOTO 61240
60670 REM ********* MOVE CURSE BACK ********
60680 IF KT = 1 GOTO 60370
60690 KT = KT - 1
60700 PRINT CHR$(8);
60710 GOTO 60370
60720 REM ********* MOVE CURSER FORWARD *********
60730 IF KT >= MAX GOTO 60370
60740 IF KT > (KTMAX + 1) GOTO 60370
60750 PRINT K$(KT);
60760 KT = KT + 1
60770 GOTO 60370
60780 REM ********** INSERT ***********
60790 IF KT > KTMAX GOTO 60370
60800 X9 = MAX
60810 WHILE X9 > KT
60820 X9 = X9 - 1
60830 K$(X9 + 1) = K$(X9)
60840 WEND
60850 K$(KT) = " "
60860 KTMAX = KTMAX + 1
60870 FOR T9 = KT TO KTMAX
60880 PRINT K$(T9);
60890 NEXT T9
60900 T6 = (KTMAX - KT) + 1
60910 FOR T7 = 1 TO T6
60920 PRINT CHR$(8);
60930 NEXT T7
60940 GOTO 60370
60950 REM ********** DELETE ***********
60960 IF KT > KTMAX GOTO 60370
60970 K$(MAX + 1) = ""
60980 X9 = KT
60990 WHILE X9 <= MAX
61000 K$(X9) = K$(X9 + 1)
61010 X9 = X9 + 1
61020 WEND
61030 KTMAX = KTMAX - 1
61040 FOR T9 = KT TO KTMAX
61050 PRINT K$(T9);
61060 NEXT T9
61070 PRINT "_";
61080 T7 = (KTMAX - KT) + 2
61090 FOR T8 = 1 TO T7
61100 PRINT CHR$(8);
61110 NEXT T8
61120 GOTO 60370
61130 REM ********* BACKSPACE ********
61140 IF KT = 1 GOTO 60370
61150 KT = KT - 1
61160 PRINT CHR$(8);
61170 K$(KT) = " "
61180 PRINT "_";
61190 PRINT CHR$(8);
61200 GOTO 60370
61210 REM ******* INPUT NOT ACCEPTABLE ********
61220 PRINT CHR$(7);
61230 GOTO 60380
61240 REM ********* CLEAR STRINGS ********
61250 MAX = LEN(A$)
61260 D2$ = ""
61270 D1$ = ""
61280 DFLG = 0
61290 FOR Q93 = 1 TO MAX
61300 R$ = MID$(A$,Q93,1)
61310 IF INSTR(DIG$,R$) = 0 GOTO 61380
61320 IF R$ = "." OR DFLG = 1 GOTO 61360
61330 IF DFLG = 1 GOTO 61360
61340 D2$ = D2$ + R$
61350 GOTO 61380
61360 D1$ = D1$ + R$
61370 DFLG = 1
61380 NEXT Q93
61390 DA# = VAL(D2$)
61400 D1# = VAL(D1$)
61410 DT# = DA# + D1#
61420 IF K$(1) = "-" THEN DT# = -DT#
61430 RETURN
61900 REM ****** CHECK FOR ASC0
61910 S4$ = INKEY$
61920 C2 = ASC(S4$)
61930 IF C2 = 83 THEN C = 1
61940 IF C2 = 82 THEN C = 6
61950 IF C2 = 75 THEN C = 19
61960 IF C2 = 77 THEN C = 4
61970 RETURN
64200 REM
64210 PRINT " ERROR NUMBER ";ERR ; " ON LINE ";ERL
64270 CLOSE
64280 PRINT " PRESS ANY KEY TO CONTINUE"
64290 IF INKEY$ = "" THEN 64290
64300 RESUME 3
R ; " ON LINE ";ERL
64270 CLOSE