|
Post by angelo2449 on Mar 22, 2024 15:41:15 GMT -5
Hi guys,
this part of one of my programs opens two files at the same time, loads the lines and adds them.
I would like to check that the length of the first file is equal to the length of the second file, to avoid the
'past end'.
How would you do it?
Thank you.
insert code here
if FileExists(LibrettoCompletoSpeciale$) then
open LibrettoCompletoSpeciale$ for input as #inUno
else
Notice "Attenzione" + chr$(13) + "Il File > LibrettoCompletoSpeciale$ < non esiste!"
wait
end if
if FileExists(Disco$ + "\Trasformer\DatiTrasformati\ConveRgo\ConveRgoFile.dat") then
open Disco$ + "\Trasformer\DatiTrasformati\ConveRgo\ConveRgoFile.dat" for input as #inDue
else
Notice "Attenzione" + chr$(13) + "Il File " + chr$(13) +_
"> Disco$ + \Trasformer\DatiTrasformati\ConveRgo\ConveRgoFile.dat < non esiste!"
wait
end if
open Disco$ + "\Trasformer\DatiTrasformati\ConveRgo\ConveRgoCompleto.dat" for output as #ou ' controlla
while eof(#inUno) = 0
line input #inUno, RigaLC$
if trim$(RigaLC$) = "" then goto [SaltaRigaCF]
line input #inDue, RigaCF$
if trim$(RigaCF$) = "" then goto [SaltaRigaCF]
print #ou, RigaCF$ + "-" + mid$(RigaLC$, 60, 11) + "," + mid$(RigaLC$, 72, 11) + "," + mid$(RigaLC$, 84, 11) 'mid$(RigaLC$, 83)
[SaltaRigaCF]
wend
' errore qui
close #inUno
close #inDue
close #ou
|
|
|
Post by tsh73 on Mar 22, 2024 22:58:23 GMT -5
Hello File length will not help you much To prevent read past end error, you would need line count. So you can open file, line input to a temp variable, count lines until eof. Or just check for eof of second file before reading from it.
|
|
honky
Junior Member
Posts: 63
|
Post by honky on Mar 23, 2024 3:55:17 GMT -5
open "données.txt" for input as #g while eof(#g)=0 n=n+1: line input #g, donn$ if donn$="" then n=n-1: goto [passa] 'remove empty lines [passa] wend close #g dim list$(n+1): n=0: dim aff$(500) 'Do not forget to reset "n" open "données.txt" for input as #g while eof(#g)=0 n=n+1: line input #g, donn$ if donn$="" then n=n-1: goto [passb] ''remove empty lines (with différent target [passa], [passb]) list$(n)=donn$ [passb] wend close #g
|
|