BBS: Inland Empire Archive Date: 02-05-93 (03:52) Number: 389 From: ROB MCKEE Refer#: NONE To: DAVID DUREL Recvd: NO Subj: BACKWARDS FILE READING Conf: (2) Quik_Bas
Hello DAVID! You wrote in a message to ALL: DD> Does anyone out there have a simple routine to read an ASCII DD> file backwards? In other words, start from the end of the DD> file and read to the beginning, instead of the other way DD> around. Something like this? For RBBS no less! <G> ' Rbbs to English master list converter ' Kludge-O-matic by Rob McKee ' Written to run under Qbasic ' FreeWare SmearWear... ' Here's the guts.. ' You can polish it if you like! DEFINT A-Z DIM a(1 TO 266) AS STRING * 80 DIM ga$(1 TO 500) Year=88 ' First Year of FileList FileName$="125_27.Lst" ' Output Name OPEN FileName$ FOR OUTPUT AS 2 FOR t = 1 TO VAL(MID$(DATE$, 9, 2)) - Year F$(t) = MID$(STR$(t + (Year-1)), 2) NEXT F$(6) = "DIR" FOR t = 1 TO VAL(MID$(DATE$, 9, 2)) - Year + 1 TheFile$ = "master." + F$(t) PRINT TheFile$: OPEN TheFile$ FOR INPUT AS 1 Ptr = 0 DO UNTIL EOF(1) ' read the file frontwards Ptr = Ptr + 1 LINE INPUT #1, a(Ptr) LOOP FOR g = Ptr TO 2 STEP -1 ' Process it backwards IF MID$(a(g), 78, 3) = " ." THEN b$ = LEFT$(a(g), 77) b$ = LTRIM$(RTRIM$(b$)) a(g) = "" IF RIGHT$(b$, 1) = "-" THEN b$ = LEFT$(b$, LEN(b$) - 1) ELSE b$ = " " + b$ END IF c$ = c$ + b$ b$ = "" ELSE ' Unwrap the Line b$ = "" b$ = LEFT$(a(g), 77) b$ = RTRIM$(b$) IF RIGHT$(b$, 1) = "-" THEN b$ = LEFT$(b$, LEN(b$) - 1) Count = Count + 1 ga$(Count) = c$ c$ = "" ' cut down on Memory usage ' things get real tight here for string space c$ = MID$(a(g), 78, 3) + " " + b$ a(g) = "" b$ = "" END IF IF INKEY$ <> "" THEN ' Pause routine DO: LOOP WHILE INKEY$ = "" END IF NEXT CLOSE 1 NEXT FOR t = 1 TO Count - 1 FOR g = Count TO t + 1 STEP -1 IF ga$(g) < ga$(t) THEN SWAP ga$(g), ga$(t) NEXT NEXT FOR t = 1 TO Count - 1 FOR g = Count TO t + 1 STEP -1 IF ga$(g) < ga$(t) THEN SWAP ga$(g), ga$(t) NEXT NEXT CLS FOR t = 1 TO Count PRINT LEFT$(ga$(t), 40) PRINT #2, ga$(t) NEXT SYSTEM Catcha Later , I'll see you on the flip side - Rob --- timEd/B6 * Origin: Another Quik_Bas Point in Richmond, CA (1:125/1212.13)
Books at Amazon:
Back to BASIC: The History, Corruption, and Future of the Language
Hackers: Heroes of the Computer Revolution (including Tiny BASIC)
Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution
The Advent of the Algorithm: The Idea that Rules the World
Moths in the Machine: The Power and Perils of Programming
Mastering Visual Basic .NET