Line Input problem 
Author Message
 Line Input problem


Quote:
> I'm trying to read a 220 mb text file from a Unix system.
> The file has carriage returns, but no line feeds.  Line
> Input will not work, which I believe is due to the missing
> line feeds which causes it to interpret the file as one
> 220 mb line.  The help docs say that it should work on a
> file with just carriage returns.  Any ideas?

Here's a repost of a similar question (and answer).  Although, you're
working with a siginficantly larger file, this approach will still work.  If
220 Mb is too much to bring into sBuffer in one shot, you can use a loop to
successively add to the buffer in chunks as your search and split needs more
data.

Quote:
> I have a question regarding reading a text file using
> sequential file access.  I have a text file a few thousand
> lines long, about 1200 character column each line.  It
> turns out that each of these lines is ended by a line feed
> character, chr(10).  Is there any way I can read this file,
> line by line, using the Line Input statement, which
> requires lines to be ended by chr(13)?

I don't think so -- I've seen the question posed before w/o the quick fix
you're hoping for.  Since your file is only a few megabytes, though, you can
read it into memory and parse it out.  Here's a quick example:

Private Sub Command1_Click()
  Dim sDelim As String
  Dim sFile As String
  Dim iFile As Long
  Dim sBuffer As String
  Dim iUsed As Long
  Dim iBreak As Long

  sFile = "c:\somebigfile.txt"

  sDelim = vbCr  'end of line delimiter
  sBuffer = Space$(FileLen(sFile))

  iFile = FreeFile
  Open sFile For Binary Access Read As iFile
  Get #iFile, , sBuffer
  Close iFile

  Do While iUsed < Len(sBuffer)
    iBreak = InStr(iUsed + 1, sBuffer, sDelim)
    If iBreak = 0 Then iBreak = Len(sBuffer) + 1

    Debug.Print Mid$(sBuffer, iUsed + 1, iBreak - iUsed - 1)
    iUsed = iBreak + Len(sDelim) - 1
  Loop
End Sub

I'm running a 1.7 GHz Pentium IV, and this loop took a second for a 10 Mb
file.



Sun, 05 Sep 2004 00:42:04 GMT  
 Line Input problem
Thanks!  I'll give that a try.

Brad

Quote:
>-----Original Message-----



>> I'm trying to read a 220 mb text file from a Unix
system.
>> The file has carriage returns, but no line feeds.  Line
>> Input will not work, which I believe is due to the
missing
>> line feeds which causes it to interpret the file as one
>> 220 mb line.  The help docs say that it should work on a
>> file with just carriage returns.  Any ideas?

>Here's a repost of a similar question (and answer).  
Although, you're
>working with a siginficantly larger file, this approach

will still work.  If
Quote:
>220 Mb is too much to bring into sBuffer in one shot, you
can use a loop to
>successively add to the buffer in chunks as your search

and split needs more

- Show quoted text -

Quote:
>data.

>> I have a question regarding reading a text file using
>> sequential file access.  I have a text file a few
thousand
>> lines long, about 1200 character column each line.  It
>> turns out that each of these lines is ended by a line
feed
>> character, chr(10).  Is there any way I can read this
file,
>> line by line, using the Line Input statement, which
>> requires lines to be ended by chr(13)?

>I don't think so -- I've seen the question posed before
w/o the quick fix
>you're hoping for.  Since your file is only a few

megabytes, though, you can

- Show quoted text -

Quote:
>read it into memory and parse it out.  Here's a quick
example:

>Private Sub Command1_Click()
>  Dim sDelim As String
>  Dim sFile As String
>  Dim iFile As Long
>  Dim sBuffer As String
>  Dim iUsed As Long
>  Dim iBreak As Long

>  sFile = "c:\somebigfile.txt"

>  sDelim = vbCr  'end of line delimiter
>  sBuffer = Space$(FileLen(sFile))

>  iFile = FreeFile
>  Open sFile For Binary Access Read As iFile
>  Get #iFile, , sBuffer
>  Close iFile

>  Do While iUsed < Len(sBuffer)
>    iBreak = InStr(iUsed + 1, sBuffer, sDelim)
>    If iBreak = 0 Then iBreak = Len(sBuffer) + 1

>    Debug.Print Mid$(sBuffer, iUsed + 1, iBreak - iUsed -
1)
>    iUsed = iBreak + Len(sDelim) - 1
>  Loop
>End Sub

>I'm running a 1.7 GHz Pentium IV, and this loop took a
second for a 10 Mb
>file.

>.



Sun, 05 Sep 2004 23:38:28 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. line input# problem - chr$(&H1A)

2. Print# And Line Input# problem.

3. LINE INPUT problem

4. code similar to Qbasic INPUT and LINE INPUT keywords

5. Input# and Line Input#

6. multi-line userform input problem

7. problem with line input

8. Problems with line input

9. Problem w/ Line Input # - VB/Win 3.0 - Help!

10. Using Line Input to go back a line

11. line input lines greater than 255 characters?

12. reading input line by line

 

 
Powered by phpBB® Forum Software