News:

Welcome to RetroCoders Community

Main Menu

GW Basic Psalms Reader

Started by ron77, Dec 16, 2023, 10:22 AM

Previous topic - Next topic

ron77

With the help from mysoft since gwbasic is limited and you can't load the entire text file in memory (you get "out of string space" error), plus you can't print lines that are over 255 chars - so mysoft coded this workaround for it - attached is "psalms.txt" database with psalms book.


140 Rem ====== PSALMS READER =========
150 Rem ==== MAIN LOOP =======
155 DIM PSALMS$(100)
160 CLS: PC =-1:C=0: Input "WHICH CHAPTER DO YOU WISH TO READ?: "; C
170 If C < 1 Or C > 150 Then GoTo 160
175 PRINT "PLEASE WAIT WHILE I LOAD PSALMS CHAPTER "; C
180 OPEN "R", #1, "psalms.txt", 128
190 CHATPERNUMBER$=""

201 FIELD #1, 128 AS sBlk$
202 iLineStart% = 0: iBigLine% = 0
210 if EOF(1) then goto 250 else gosub 9000
211 P1 = INSTR(SLINE$,":")
220 CHATPTERNUMBER$ = MID$(SLINE$, 1, P1-1)
230 IF VAL(CHATPTERNUMBER$) = C THEN PC = PC + 1:PSALMS$(PC) = SLINE$
235 REM IF VAL(CHATPTERNUMBER$) > C goto 250
240 GOTO 210
250 CLOSE #1
260 Rem ====== DONE READING FILE =========
270 Rem ====== DISPLAYING PSALMS =========
280 CLS
290 PRINT "PSALMS CHAPTER "; C
300 PRINT "================"
310 PRINT
320 FOR I = 0 TO PC
325 IF I MOD 8 = 0 THEN :PRINT: PRINT "PRESS ANY KEY TO CONTINUE":WHILE INKEY$="": WEND:CLS: PRINT "PSALMS CHAPTER "; C: PRINT "================": PRINT
330 PRINT PSALMS$(I); " "
340 NEXT I 
350 PRINT
360 PRINT "================"
370 PRINT
380 PRINT "PRESS ANY KEY TO CONTINUE"
390 WHILE INKEY$ = "": WEND
400 CLS
410 Rem ====== DONE DISPLAYING PSALMS =========
420 Rem ====== ASKING FOR NEXT CHAPTER =========
430 Input "DO YOU WISH TO READ ANOTHER CHAPTER? (Y/N): "; A$
440 If A$ = "Y" Or A$ = "y" Then GoTo 160
450 If A$ = "N" Or A$ = "n" Then GoTo 460
460 CLS
470 PRINT "THANK YOU FOR USING PSALMS READER"
480 END

9000 'Read the next line into sLine$ (iBigLine%=1 if line got truncated)
9005 sLine$ = "": iCRLF% = 1: IF sBuf$ = "" THEN 9080
9010 N% = INSTR(sBuf$, CHR$(13))
9015 IF N% = 0 THEN 9055
9020   IF (LEN(sLine$) + N% - 1) > 255 THEN 9045
9025     sLine$ = sLine$ + LEFT$(sBuf$, N% - 1)
9030     sBuf$ = MID$(sBuf$, N% + 1): IF iCRLF% <> 0 AND sBuf$ = "" THEN LastR% = 1
9035     IF iCRLF% <> 0 AND LEFT$(sBuf$, 1) = CHR$(10) THEN sBuf$ = MID$(sBuf$, 2)
9040     iBigLine% = 0: RETURN
9045   N% = 256 - LEN(sLine$): sLine$ = sLine$ + LEFT$(sBuf$, N% - 1)
9050   sBuf$ = MID$(sBuf$, N%): iBigLine% = 1: RETURN
9055 N% = INSTR(sBuf$, CHR$(10)): iCRLF% = 0: IF N% THEN 9020
9060 IF (LEN(sLine$) + LEN(sBuf$)) < 256 THEN 9075
9065   N% = 256 - LEN(sLine$): sLine$ = sLine$ + LEFT$(sBuf$, N% - 1)
9070   sBuf$ = MID$(sBuf$, N%): iBigLine% = 1: RETURN
9075 sLine$ = sLine$ + sBuf$: sBuf$ = ""
9080 IF EOF(1) THEN iBigLine% = 0: RETURN
9085 GET #1: sBuf$ = sBlk$: iCRLF% = 1
9090 IF LastR% <> 0 AND ASC(sBuf$) = 10 THEN sBuf$ = MID$(sBuf$, 2)
9095 LastR% = 0: GOTO 9010

You cannot view this attachment.