Results 1 to 11 of 11

problem in reading new text file in VB script macro

Threaded View

  1. #5
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    49,644

    Re: problem in reading new text file in VB script macro

    For the sake of simplicity, I have produced a free-standing conversion in Excel.

    It works in much the same way as your current Excel application.

    However, rather than taking the text file and converting it to Excel, it takes a "new format" text file and converts it to an "old format" text file. This can then be read by the original converter.

    Sub EdiConversion()
    
    Dim TxtFile As Variant
    Dim TxtFileOut As Variant
    Dim EdiRows As String
    Dim Edirow As Variant
    Dim i As Long
    
    ' Ask for the file name that has to be processed
    TxtFile = Application.GetOpenFilename("Text Files (*.txt), *.txt")
    If TxtFile = False Then
        MsgBox "No files selected, nothing to do. Bye."
        Exit Sub
    End If
    
    ' Open the file and read rows processing them one by one
    Open TxtFile For Input Access Read As #1
    TxtFileOut = Left(TxtFile, Len(TxtFile) - 4) & "_OF.txt"
    Open TxtFileOut For Output Access Write As #2
    
    While Not EOF(1)
        Line Input #1, EdiRows
        Edirow = Split(EdiRows, "'")
        For i = LBound(Edirow) To UBound(Edirow)
            If Edirow(i) <> "" Then
                Print #2, Edirow(i) & "'"
           End If
        Next i
    Wend
    
    Close #1
    Close #2
    
    MsgBox "The file has been converted" & vbLf & vbLf & _
           "Input:      " & TxtFile & vbLf & _
           "Output:  " & TxtFileOut & vbLf, , _
           "Edi File Conversion"
    
    End Sub

    It probably wouldn't be too difficult to combine this with the original but I think it's better, at this stage, to "prove the theory" before hacking the original about.

    I trust it will help.

    Regards
    Attached Files Attached Files

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1