Read a specific line from a file: Difference between revisions

Content added Content deleted
Line 1,005: Line 1,005:


=={{header|FutureBasic}}==
=={{header|FutureBasic}}==
Uses FB's native file$ command that opens a dialog window and allows the user to select the file to read.
Uses FB's openpanel command that opens a dialog window and allows the user to select the file to read.
<lang futurebasic>
<lang futurebasic>window 1
include "ConsoleWindow"


dim as long i : i = 1
long i = 1
dim as Str255 s, lineSeven
Str255 s, lineSeven
dim as CFURLRef url
CFURLRef url


if ( files$( _CFURLRefOpen, "TEXT", "Select text file", @url ) )
url = openpanel 1, @"Select text file"
if ( url )
open "I", 2, @url
open "I", 2, url
while ( not eof(2) )
while ( not eof(2) )
line input #2, s
line input #2, s
if ( i == 7 )
if ( i == 7 )
lineSeven = s
lineSeven = s
end if
end if
i++
i++
wend
wend
close 2
close 2
if ( lineSeven[0] )
print lineSeven
else
print "File did not contain seven lines, or line was empty."
end if
end if
end if


HandleEvents</lang>
if ( lineSeven[0] )
print lineSeven
else
print "File did not contain seven lines, or line was empty."
end if
</lang>


Input text file:
Input text file: