Deleting carriage return

  • 13 years ago
    I have the following code to amalgamate data from 3 text files into 1. How do I delete the carriage return at the end of the file using VBA?
    Public Sub CreateInternetFile(strFileCount, strFileInternetExportRanging, strFileInternetExportProducts)

    Dim intChannel As Integer

    For intChannel = 1 To 511
    Close #intChannel
    Next intChannel

    Open strFileCount For Append As #1
    Open strFileInternetExportRanging For Input As #2
    Open strFileInternetExportProducts For Input As #3

    While Not EOF(2)
    Line Input #2, InputString
    Print #1, InputString

    While Not EOF(3)
    Line Input #3, InputString
    Print #1, InputString

    Close #1
    Close #2
    Close #3

    End Sub

  • 13 years ago
    Shared Function ReadFile$(path$) ...
    Dim f1$ = ReadFile(path1).TrimEnd(vbCr, vbLf)
    WriteFile(f1 & f2 & f3)

  • 13 years ago

    MS Access doesn't recognise TrimEnd as a function!

  • 13 years ago
    So you can maybe use this:?

    Function rlCrLfs$(strng$)
     If Len(strng) < 2 Then
      rlCrLfs = strng
      Dim ret$ = strng
      Dim crlf$ =

    Chr(13) & Chr(10)
      While Right(ret,2) = crlf
       ret = Left(ret, Len(ret) - 2)

    rlCrLfs = ret
     End If
    End Function

Post a reply

Enter your message below

Sign in or Join us (it's free).


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In order to understand recursion, one must first understand recursion.”