Qbasicnews.com
help with file reading - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Discussion & Programming Help (http://qbasicnews.com/newforum/forum-11.html)
+--- Thread: help with file reading (/thread-228.html)



help with file reading - Lanzaa - 02-17-2003

is there any way i can make this program better in terms of file accecing?
Code:
CLS
OPEN "blank.txt" FOR INPUT AS #1
INPUT #1, a$
FOR letter = 1 TO LEN(a$)
b = ASC(MID$(a$, letter, 1))
SELECT CASE b
    CASE 65 TO 90
        b = (((b - 65) + 1) MOD 26) + 65
    CASE 97 TO 122
        b = (((b - 97) + 1) MOD 26) + 97
END SELECT
MID$(a$, letter, 1) = CHR$(b)
NEXT letter
CLOSE #1
OPEN "blank.txt" FOR OUTPUT AS #1
WRITE #1, a$
PRINT a$
CLOSE #1
and any other sugetions are good, but i dont want peek and poke yet


help with file reading - na_th_an - 02-17-2003

PEEK and POKE not needed. The program is OK, but I'd change INPUT for LINE INPUT and WRITE # for PRINT #.


help with file reading - Agamemnus - 02-17-2003

you might want to use UCASE$ or LCASE$ too.

Code:
CLS
OPEN "blank.txt" FOR INPUT AS #1
LINE INPUT #1, a$
FOR I% = 1 TO LEN(a$)
j% = ASC(LCASE$(MID$(a$, I%, 1)))
MID$(a$, letter, 1) = CHR$(j%-65)
NEXT I%
CLOSE #1

OPEN "blank.txt" FOR OUTPUT AS #1
PRINT #1, a$
PRINT a$
CLOSE #1