Read a specific line from a file: Difference between revisions
Content added Content deleted
(Frink) |
(Read a specific line from a file in various BASIC dialents (BASIC256, QBasic, True BASIC and Yabasic)) |
||
Line 264: | Line 264: | ||
} |
} |
||
</lang> |
</lang> |
||
=={{header|BASIC}}== |
|||
==={{header|BASIC256}}=== |
|||
<lang basic256>f = freefile |
|||
filename$ = "input.txt" |
|||
open f, filename$ |
|||
lineapedida = 7 |
|||
cont = 0 |
|||
while not (eof(f)) |
|||
linea$ = readline(f) |
|||
cont += 1 |
|||
if cont = lineapedida then |
|||
if trim(linea$) = "" then print "The 7th line is empty" else print linea$ |
|||
exit while |
|||
end if |
|||
end while |
|||
if cont < lineapedida then print "There are only "; cont; " lines in the file" |
|||
close f |
|||
end</lang> |
|||
==={{header|QBasic}}=== |
|||
{{works with|QBasic}} |
|||
<lang QBasic>f = FREEFILE |
|||
OPEN "input.txt" FOR INPUT AS #f |
|||
lineapedida = 7 |
|||
cont = 0 |
|||
DO WHILE NOT EOF(f) |
|||
LINE INPUT #f, linea$ |
|||
cont = cont + 1 |
|||
IF cont = lineapedida THEN |
|||
IF linea$ = "" THEN PRINT "The 7th line is empty" ELSE PRINT linea$ |
|||
EXIT DO |
|||
END IF |
|||
LOOP |
|||
IF cont < lineapedida THEN PRINT "There are only "; cont; " lines in the file" |
|||
CLOSE #1</lang> |
|||
==={{header|True BASIC}}=== |
|||
<lang qbasic>LET filename$ = "input.txt" |
|||
OPEN #1: NAME filename$, ORG TEXT, ACCESS INPUT, CREATE OLD |
|||
LET lineapedida = 7 |
|||
LET cont = 0 |
|||
DO |
|||
LINE INPUT #1: linea$ |
|||
LET cont = cont + 1 |
|||
IF cont = lineapedida THEN |
|||
IF TRIM$(linea$) = "" THEN PRINT "The 7th line is empty" ELSE PRINT linea$ |
|||
EXIT DO |
|||
END IF |
|||
LOOP UNTIL END #1 |
|||
IF cont < lineapedida THEN PRINT "There are only "; cont; " lines in the file" |
|||
CLOSE #1 |
|||
END</lang> |
|||
==={{header|Yabasic}}=== |
|||
<lang yabasic>filename$ = "input.txt" |
|||
open filename$ for reading as #1 |
|||
lineapedida = 7 |
|||
cont = 0 |
|||
while not eof(#1) |
|||
line input #1 linea$ |
|||
cont = cont + 1 |
|||
if cont = lineapedida then |
|||
if trim$(linea$) = "" then print "The 7th line is empty" else print linea$ : fi |
|||
break |
|||
end if |
|||
wend |
|||
if cont < lineapedida print "There are only ", cont, " lines in the file" |
|||
close #1 |
|||
end</lang> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |