Microsoft KB Archive/31790

Using SORTM.EXE to Sort BASIC RANDOM Access Files PSS ID Number: Q31790 Article last modified on 07-14-1988 PSS database name: B_SORT

1.01

MS-DOS

B_QuickBas Summary: The information below describes how to create a file with RANDOM access in Microsoft BASIC, and then sort it with Microsoft SORT (Standalone) Version 1.01 for MS-DOS.

More Information: To sort a Microsoft BASIC file created with RANDOM access, RANDOM must be specified as the file organization [fileorg] in the INPUT and OUTPUT statements for SORTM.EXE. For information on sorting other file organizations supported by Microsoft SORT, see Table 6, “MS SORT File Organizations,” on Page 37 of the “Microsoft SORT Sorting and Merging Facility for MS-DOS: Reference Manual: Microsoft Standalone Version.” See Pages 35-37 and 40-42 for descriptions of the INPUT and OUTPUT statements. Note that the EXAMPLE.SRT source code shown on Page 9 does not sort BASIC RANDOM access files. EXAMPLE.SRT sorts an ASCII text file. The sample data file, DATA.IN provided on the MS SORT Version 1.10 diskette, is an ASCII text file. By definition, an ASCII text file contains only standard ASCII characters, and each record is terminated by a carriage return and linefeed pair. These ASCII text files are created in BASIC with sequential access, not RANDOM access. The following steps describe how to create a file with RANDOM access in Microsoft BASIC, and then sort it with Microsoft SORT (Standalone) Version 1.01:

  Run the following BASIC program to create DATA2.IN (this BASIC program inputs 10 names and writes them to a file called DATA2.IN): OPEN “data2.in” FOR RANDOM AS #1 FIELD #1, 12 AS a$, 10 AS b$ FOR k = 1 TO 10 INPUT “first,last”; c$, d$  LSET a$ = c$ LSET b$ = d$ PUT #1, k NEXT k CLOSE #1   Modify the EXAMPLE.SRT program (on Page 9) as follows and save it as EXAMPLE2.SRT: INPUT “DATA2.IN” RANDOM KEY [1:12] OUTPUT “SORT2.OUT” RANDOM   Sort the file DATA2.IN into SORT2.OUT with SORTM.EXE from the DOS command line, as follows: SORTM EXAMPLE2.SRT   The following BASIC program displays the newly sorted contents of the SORT2.OUT RANDOM file: OPEN “sort2.out” FOR RANDOM AS #1 FIELD #1, 12 AS a$, 10 AS b$ FOR k = 1 TO 10 GET #1, k PRINT a$, b$  NEXT k CLOSE #1 

Copyright Microsoft Corporation 1988.