Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2009
    Posts
    35

    Unanswered: How to step through an input text file?

    Hi, can anybody help or at least point me in the right direction. I have a text file :

    TCS
    LIN01
    Lin02
    Lin03
    TCS
    Lin01
    Lin02
    PTC
    Lin01
    Lin02
    TCS
    Lin01
    Lin02
    LPL
    Lin01
    Lin01

    Basically it is a list of different coupon types with their corresponding lines. What I need is a function that will allow me pick JUST the TCS and their lines and output them to a new file. I can output the TCS but i need the code to skip all other coupon types and their lines.

    The code I have attached may not be relevant as this inserts "000" into the line. But this can be changed to just output the TCS coupons.

    Do Until EOF(intInHandle)
    Line Input #intInHandle, strInLine
    If Left(strInLine, 4) = "TCS " Then
    strOutLine = Left(strInLine, 11) & "000" & Mid(strInLine, 12)
    Else
    strOutLine = strInLine
    End If

    Basically it is a function that allows the code to step through each line or go to next line?

    Thanks

  2. #2
    Join Date
    Nov 2007
    Location
    Adelaide, South Australia
    Posts
    4,049
    Sounds easy enough. Sample output please.

    That code is missing the loop end and the definition of intInHandle btw. You should post more complete code, it makes it easier to help you.
    Owner and Manager of
    CypherBYTE, Microsoft Access Development Specialists.
    Microsoft Access MCP.
    And all around nice guy!


    "Heck it's something understood by accountants ... so it can't be 'that' difficult..." -- Healdem
    "...teach a man to code and he'll be frustrated for life! " -- georgev

  3. #3
    Join Date
    Feb 2009
    Posts
    35
    Here is the full code :

    Option Compare Database
    Option Explicit

    Function InptoOutHandler(InFile As String, OutFile As String)

    Dim intInHandle As Integer
    Dim intOutHandle As Integer
    Dim strInLine As String
    Dim strOutLine As String

    intInHandle = FreeFile
    Open InFile For Input As #intInHandle
    intOutHandle = FreeFile
    Open OutFile For Output As #intOutHandle
    Do Until EOF(intInHandle)
    Line Input #intInHandle, strInLine
    If Left(strInLine, 6) = "CPNTCS" Then
    strOutLine = Left(strInLine, 59) & "000" & Mid(strInLine, 60)
    Else
    strOutLine = strInLine
    End If
    Print #intOutHandle, strOutLine
    Loop
    Close #intOutHandle
    Close #intInHandle
    End Function

    I have attached the sample output file
    Attached Files Attached Files

Posting Permissions

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