home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
World of Shareware - Software Farm 2
/
wosw_2.zip
/
wosw_2
/
QBAS
/
SORTOR1.ZIP
/
SORTOR.TXT
Wrap
Text File
|
1990-09-18
|
2KB
|
89 lines
SUB CompressSort STATIC
DIM Option$(3)
ClearBottom
Option$(1) = "Compress and Sort Database"
Option$(2) = "Compress Only"
Option$(3) = "Return to Main Menu"
Menu = OptionMenu(Option$(), 1, ":1:", Scan)
IF Scan THEN EXIT SUB
ClearBottom
SELECT CASE Menu
CASE 1
LoadBase 0
IF ErrorOccured THEN EXIT SUB
ClearBottom
Rec$ = ""
FOR Kount = 1 TO FieldKount
Rec$ = Rec$ + TypeMask$(FInfo(Kount).FType, FInfo(Kount).Length)
NEXT Kount
FieldNum = SelectField(Rec$)
IF FieldNum = 0 THEN
CLOSE
FOR Kount = 3 TO 19
LOCATE Kount, 2: PRINT SPACE$(78);
NEXT Kount
EXIT SUB
END IF
Start = FInfo(FieldNum).Start
Length = FInfo(FieldNum).Length
ClearBottom
CASE 2
LoadBase 1
IF ErrorOccured THEN EXIT SUB
CASE 3
EXIT SUB
END SELECT
LOCATE 21, 3: PRINT "Compressing Database...";
OPEN Filename$ + ".TMP" FOR RANDOM AS 2 LEN = BaseLen
FIELD #2, BaseLen AS Record2$
FOR Kount = 1 TO RecordKount
GET #1, Kount
IF LEFT$(Record$, 1) <> CHR$(255) THEN
LSET Record2$ = Record$
PUT #2
END IF
NEXT Kount
IF Menu = 1 THEN
ClearBottom
LOCATE 21, 3: PRINT "Sorting Database...";
RecordKount = LOF(2) \ BaseLen
Offset = RecordKount \ 2
DO WHILE Offset > 0
Limit = RecordKount - Offset
DO
Switch = 0
FOR Kount = 1 TO Limit
GET #2, Kount
Sort$ = Record2$
GET #2, Kount + Offset
Sort1$ = Record2$
IF MID$(Sort$, Start, Length) > MID$(Sort1$, Start, Length) THEN
LSET Record2$ = Sort1$
PUT #2, Kount
LSET Record2$ = Sort$
PUT #2, Kount + Offset
Switch = Kount
END IF
NEXT Kount
Limit = Switch - Offset
LOOP WHILE Switch
Offset = Offset \ 2
LOOP
FOR Kount = 3 TO 19
LOCATE Kount, 2: PRINT SPACE$(78);
NEXT Kount
END IF
CLOSE
KILL Filename$ + ".DAT"
NAME Filename$ + ".TMP" AS Filename$ + ".DAT"
END SUB