Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File Input - Length problem

Status
Not open for further replies.

TyGwyn

Programmer
Oct 5, 2005
31
0
0
GB
I have a text file that I am opening using

Open myfile.txt for Input as #1


I am then doing some text movement with a loop using

Do Until (EOF(1) = True)
Line Input #1, Variablelist
Loop

PROBLEM the text file I am opening is 1600 lines, when I use
Loc(1) to find the length of file I have only opened to line 653, and this is also reflected in the text movement I am doing within the Line Input Loop?

What is happening to the remaining 900+ lines of text.


Any help gratefully received.

Thanks

Adam

 
This is kind of an archaic way to do what you're trying to do. You might want to investigate the FileSystemObject if you don't get an answer.

HTH

Bob
 
Thanks, i am a bit archaeic myself, will take a look at FileSystemObject.

Adam.
 
I did try to recreate your problem by:

Have a txt file with 1600 lines of text and try this code:
Code:
Dim Variablelist As String
Dim i As Integer

Open "C:\1600lines.txt" For Input As #1

Do Until (EOF(1) = True)
    i = i + 1
    Line Input #1, Variablelist
    If i > 1595 Then
        Debug.Print Variablelist
    End If
Loop

Close #1

And it works like a dream, no problem, displaying all 1600 lines of text.

DO you do anything different in your code?

---- Andy
 
Thanks, it appears to be a problem with LOC(#) not returning the correct line number at the end of file, I have used a variable increment and read the lines in to this value, works fine, don't understand why LOC(#) is not giving me the correct value.

Thanks all for help.

Adam
 
>don't understand why LOC(#) is not giving me the correct value

Because LOC, when used with a sequential file, provides the current byte position in the file divided by 128 (and not the line number)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top