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 Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Line Input

Status
Not open for further replies.

SUNRlSE

Programmer
Jan 8, 2002
43
GB
Hi all

I've got a problem with Line Input.

When I open a smallish file for input, I can read the first line to a string.

However one of the files I need to read is 5.9 meg, By my reckoning the file size shouldn't make a difference as VB holds the file open with a pointer to position, BUT as soon as VB tries to execute the line input everything immediatly locks and goes to not responding.

I can paste the first few lines from the file to a smaller file and that reads fine.

Is there a limitation on file size???
Try it and see.
Thanks.

Give a man a program and tomorrow he will be hungry.
Teach a man to program and he will never hunger again.
--Sunr¿se

 
If there is a limitation, I am not personally aware of it...

Have you considered reading the file through DAO or ADO? That might be a solution, so long as you can specify the delimiter as something ridiculous...
 
Your reckoning is right. It shouldn't make a difference. Can you post any of the your code where the problem is happening so that we can make some more informed observations?
 
Hmm... Makes you wonder if there's something silly in the data...
 
This is the code where it hangs.
It was done very quick so I know its sloppy, no text
dereferences etc



Private Sub Split_Click()
On Error Resume Next

If (CInt(txtFields) < 1) Or (CInt(txtFields) > 4) Then
MsgBox &quot;Fields must be 1 - 4&quot;
Exit Sub
End If
Screen.MousePointer = vbHourglass
iHandle = FreeFile
Open txtInputFile For Input As #iHandle
iHandleOut = FreeFile
Open txtOutputFile For Output As #iHandleOut
While Not EOF(iHandle)

Line Input #iHandle, sTemp <-----hangs if file is 5.9M

If (CInt(txtFields) > 0) And (Len(sTemp) >= CInt(Trim(txtLen1))) Then
s1 = Trim(Left(sTemp, Trim(txtLen1)))
sTemp = Trim(Right(sTemp, (Len(sTemp) - CInt(Trim(txtLen1)))))
If (CInt(txtFields) > 1) And (Len(sTemp) >= CInt(Trim(txtLen2))) Then
s2 = Trim(Left(sTemp, Trim(txtLen2)))
sTemp = Trim(Right(sTemp, (Len(sTemp) - CInt(Trim(txtLen2)))))
If (CInt(txtFields) > 2) And (Len(sTemp) >= CInt(Trim(txtLen3))) Then
s3 = Trim(Left(sTemp, Trim(txtLen3)))
sTemp = Trim(Right(sTemp, (Len(sTemp) - CInt(Trim(txtLen3)))))
If (CInt(txtFields) > 3) Then
s4 = Trim(Left(sTemp, Trim(txtLen4)))
End If
End If
End If
End If
Select Case CInt(txtFields)
Case 1: sOut = s1
Case 2: sOut = s1 & txtDelimit & s2
Case 3: sOut = s1 & txtDelimit & s2 & txtDelimit & s3
Case 4: sOut = s1 & txtDelimit & s2 & txtDelimit & s3 & txtDelimit & s4
End Select
Print #iHandleOut, sOut
DoEvents
Wend
Close #iHandle
Close #iHandleOut
Screen.MousePointer = vbDefault
MsgBox &quot;Done&quot;
End Sub Give a man a program and tomorrow he will be hungry.
Teach a man to program and he will never hunger again.
--Sunr¿se

 
Hi,

The Line Input # statement reads from a file one character at a time until it encounters a carriage return (Chr(13)) or carriage return–linefeed (Chr(13) + Chr(10)) sequence

A variable-length string can contain up to approximately 2 billion (2^31) characters

These two items I got from msdn.If the 5.9 Mb file doesn't have any carriage returns or linefeeds then maybe the Line Input statement is trying to build you a string one character at a time and without a DoEvents it will lock the system until it is done.

Jon
 
I can copy the file to Another and just delete the last three quarters so to vb the file is exactly the same just shorter....this works fine.

Its as though it has to process the whole file before doing the line input.

The shorter the file is the quicker line input becomes EVEN with identical first few lines ???

Thanks for all the help Give a man a program and tomorrow he will be hungry.
Teach a man to program and he will never hunger again.
--Sunr¿se

 
Not really a soloution for Line Input, but you could just read the whold thing into a single variable with a GET statement.

Create a string var, and fill it with blanks Space(LOF(#iHandle). Do a get on the file with the position as 1. The var will have the WHOLE thing - and much more quickly than line input (over the entire file). Check the file for whatever. one use might be to see if there are any cr/lf's in it. Another might be to process the info dircetly from the single var.

MichaelRed
m.red@att.net

There is never time to do it right but there is always time to do it over
 
Thanks All.
I've re-written in C++. That tends to be a lot better at things like this involving buffers and memory addressing.
Problem now solved.
Cheerz. Give a man a program and tomorrow he will be hungry.
Teach a man to program and he will never hunger again.
--Sunr¿se

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top