Results 1 to 2 of 2

Thread: Line Input# with just chr(10)

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 1999
    Location
    Catonsville, MD, USA
    Posts
    4

    Unhappy

    I have a need to be able to use the Line input# function to read one line of a text file into a variable however some lines only end with vblf (chr(10)) , not the usual vbcr & vblf (chr(13) chr(10)). Any ideas on how to make this work without re-writing the whole Line Input# function? Any help would be greatly appreciated.

    Thanks,
    Mike
    Mike

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177
    Try something like:
    Code:
    Private Sub Command1_Click()
        Dim iFile As Integer
        Dim sFile As String
        Dim sLine As String
        Dim nPos As Long
        
        iFile = FreeFile
        
        Open "C:\TheFile.txt" For Binary Access Read As iFile
            sFile = Space(LOF(iFile))
            Get #iFile, , sFile
        Close iFile
        
        sFile = Replace(sFile, Chr(13), "")
        
        Do
            nPos = InStr(sFile, Chr(10))
            If nPos = 0 Then nPos = Len(sFile) + 1
            sLine = Left(sFile, nPos - 1)
            MsgBox sLine
            sFile = Mid(sFile, nPos + 1)
        Loop While Len(sFile)
            
        
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width