Question

I need to read some basic code. I never worked with BASIC and ask you help me. There is such code

filedialog "Open","*.txt",file$
 if file$="" then end
open file$  for input as #f
'open "g:\data\funcfirstques.txt" for input as #f

while not(eof(#f))
  line input #f, a$
  i=i+1
wend
close #f
nrows=i

open "g:\data\junk.txt" for output as #1
print#1, a$
close #1

open "g:\data\junk.txt" for input as #1
while not(eof(#1))
input #1, b$
k=k+1
wend
close #1

As I understood, here is opening file file$, then in first loop, counting lines in this file and adding they to array a$. Then opening file junk.txt and writing array a$ to this file. But what is doing in second loop? What is the k?

Input is usual .csv file.

Thanks.

P.S Sorry for my awful English :)

Was it helpful?

Solution

Its reading the file

As you know from this

open "g:\data\junk.txt" for output as #1
print#1, a$
close #1

like open for OUTPUT and PRINT #

similarly this...

open "g:\data\junk.txt" for input as #1
while not(eof(#1))
input #1, b$
k=k+1
wend

is reading the file back IN byte by byte.

OTHER TIPS

Corrected code for reading a file:

filedialog "Open","*.txt",file$
IF file$ = "" THEN END
OPEN file$ FOR INPUT AS #1
'OPEN "g:\data\funcfirstques.txt" FOR INPUT AS #1
OPEN "g:\data\junk.txt" FOR OUTPUT AS #2
WHILE NOT EOF(1)
    LINE INPUT #1, a$
    PRINT #2, a$
    i = i + 1
WEND
nrows = i
CLOSE #1, #2
OPEN "g:\data\junk.txt" FOR INPUT AS #1
WHILE NOT EOF(1)
    INPUT #1, b$
    k = k + 1
WEND
CLOSE #1
PRINT "File has"; k; " lines."
END
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top