hmonnier
New Member
Enjoying Life
Posts: 27
|
Post by hmonnier on Nov 24, 2018 13:31:00 GMT -5
I am comparing 2 files looking for specific matches. Once i get a hit, i write out the match, but need a way to get the main file, the searchd file back to the beginning of the file after it has hit EOF from the first pass. Code below, no laughing!!!! I'm new....
There is a restore in there, which did not fly. I thought there was a way to rewind. The only thing i did not try as a close, then a reopen, but that seemed silly.... maybe that's it...
=================source file=================
' compare files...
' reset variables
flag=0
rec=0
' first prepare the files
OPEN "2ltest.txt" FOR INPUT AS #linfile
OPEN "1dtest.txt" FOR INPUT AS #dinfile
OPEN "outfile.txt" for OUTPUT AS #outfile
' now scan the two files for a match, and
' if so write the matched names
DO UNTIL EOF(#linfile) = -1
INPUT #linfile, l$
INPUT #dinfile, d$
'GOSUB [lookup]
DO UNTIL EOF(#dinfile) = -1
IF l$ = d$ THEN
PRINT #outfile,l$
rec=rec+1
print rec;l$
RESTORE #dinfile
else
INPUT #dinfile,d$
end if
LOOP
LOOP
' shut down the files
close #linfile
close #dinfile
close #outfile
stop
' that's all folks
|
|
|
Post by tsh73 on Nov 24, 2018 15:07:20 GMT -5
Try SEEK (look in a help file)
open "test.txt" for output as #1 for i = 1 to 5 print #1, i next close #1
open "test.txt" for input as #2
while not(eof(#2)) line input #2, a$ print a$ wend print "--second try--"
seek #2, 0 'rewind while not(eof(#2)) line input #2, a$ print a$ wend
close #2
|
|
hmonnier
New Member
Enjoying Life
Posts: 27
|
Post by hmonnier on Nov 25, 2018 9:12:02 GMT -5
Thanks, that did correct that one thanks.....
|
|
hmonnier
New Member
Enjoying Life
Posts: 27
|
Post by hmonnier on Nov 25, 2018 9:48:01 GMT -5
How do you insert code in that box and keep the indent formatting??
|
|
|
Post by tsh73 on Nov 25, 2018 13:35:02 GMT -5
that's button with "C" on a toolbar It inserts tags for code, you can write them yourself [сode]insert code here[/сode] (don't copy mine - I changed single character so it shows instead of working) Code inside tags retains indents.
|
|
|
Post by Rod on Nov 25, 2018 13:45:42 GMT -5
If your file is large you will find it is faster to load the entire file to a string variable and then parse out the phrase you are interested in with instr() Inputing from a large file slows things down. But a short file will execute in milliseconds so don't change anything if it is fast enough already.
|
|