Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2008

    Unanswered: I am parsing a | delimited txt file to a tab delimited file - HELP

    Hi, I am in the process of delimiting a | file to a tab delimited file. I have everything working except I am triing to get rid of spaces. Can someone take a look at my code and let me know what I'm doing wrong?

    Dim ImportFile As String
    Dim ExportFile As String
    Dim strInputString As String
    Dim strOutputString As String
    Dim strInputFile As String
    Dim strOutputFile As String
    Dim varSplit As Variant
    Dim intUB As Integer
    Dim intCount As Integer

    If txtImport.Value = "" Then
    MsgBox "You must enter a file to import", vbCritical, "ERROR"
    Exit Sub
    End If

    If Nz("txtImport.value", "") = "" Then
    MsgBox "Not a valid path or file", vbCritical, "ERROR"
    Exit Sub
    End If

    ImportFile = txtImport.Value
    ExportFile = txtExport.Value & "\TestOutput.txt"

    'test = ConvertTextFile(ImportFile, ExportFile)

    strInputFile = ImportFile
    strOutputFile = ExportFile

    Open strInputFile For Input As #1
    Open strOutputFile For Output As #2

    Do Until EOF(1)
    Line Input #1, strInputString
    varSplit = Split(RTrim(strInputString), "|", , vbTextCompare)
    intUB = UBound(varSplit)
    intCount = 0
    While intCount <> intUB + 1
    'strOutputString = strOutputString & varSplit(intCount) & Chr(9)
    strOutputString = strOutputString & varSplit(intCount) & vbTab
    intCount = intCount + 1
    Print #2, strOutputString
    strOutputString = ""
    intUB = 0
    Close #1
    Close #2

    Thanks for your help!

  2. #2
    Join Date
    Nov 2007
    Adelaide, South Australia
    Try changing

    Print #2, strOutputString


    Print #2, Trim(strOutputString)
    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
    Nov 2004
    out on a limb
    Provided Answers: 59
    have you considered using the replace() function instead of splitting the string into an array and then recreating the the string with the tab char. it shold be quicker, use less resources. whlt you are at it I'd write the changed line to the file rather than build one humungous string and then write that to the file.

    mytargetstring = replace(mysourcestring,"|",vbtab)

    Open strInputFile For Input As #1
    Open strOutputFile For Output As #2
    Do Until EOF(1) 'should ths be #1?
    Line Input #1, strInputString
    strOutputString = replace(strInputString,"|",vbtab)
    Print #2, strOutputString
    Close #1
    Close #2
    that will leave any leading or trailing spaces, you may need to use the TRIM function as Startrekker suggests
    the only thing Im not certain about is how replace will handle the vbtab constant.. I don't see why it won't work, but it may not
    I'd rather be riding on the Tiger 800 or the Norton

Posting Permissions

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