+ Reply to Thread
Results 1 to 1 of 1

Problems with printing in a text file

Hybrid View

  1. #1
    Registered User
    Join Date
    02-22-2011
    Location
    Philippines
    MS-Off Ver
    Excel 2007
    Posts
    25

    Problems with printing in a text file

    Hello can someone please help me with my code? I am trying to print a series of transactions in a text file but in the end, my text file is blank ;( Can someone pls. help? I'm not so sure what's wrong with it.

    Any help is greatly appreciated :D

    Sub openFile()
    '
    ' openFile Macro
    ' Macro recorded 5/28/2003 by jojo_r
    Dim data As String
    On Error GoTo ErrorTrap
        Open Cells(1, 2) For Input As #1
        Open Cells(2, 2) For Output As #2
       ' Open Cells(3, 2) For Output As #3
        
        Dim myArray As Variant
        Dim ctr As Integer
        ReDim myArray(1 To 20) As Variant
        Dim strTot As Double
        strTot = 0
        r = 5
        strtemp = ""
        transref = 1
        xcntr = 0
        Cells(3, 2) = 0
        Cells(3, 4) = 0
        strordering = Cells(4, 2)
        strAccntNo = "200285018"
      
         Dim strtemp1 As String
        
        Do While Not EOF(1)
            
            For ctr = 1 To 20
                Line Input #1, myArray(ctr)
    
                If EOF(1) Then
                    Exit For
                End If
            Next ctr
         
            ctr2 = 1
            
       Do Until ctr2 = ctr + 1
     
            strtemp1 = Trim(Mid(myArray(ctr2), 91, 8))
            If strtemp1 = Trim(Mid(myArray(ctr2), 91, 8)) Then
                    strbene = Trim(Mid(myArray(ctr2), 51, 40))
                    strnetamt1 = Trim(Mid(myArray(ctr2), 172, 15))
                    trans_ref = Trim(Mid(myArray(ctr2), 91, 8))
                    strdelmet = ReturnDeliveryMethod
                    Cells(6, 14) = strbene
                    strTot = strTot + strnetamt1
                    ctr2 = ctr2 + 1
            Else
                strLine = "PLC@" & "PH@" & _
                        strAccntNo & "@" & "PHP" & "@" & Format(strTot, "###0.#0") & "@@" & Format(Now, "MMDDYYYY") & "@" & Format(trans_ref, "00000000") & "@@" & "@@@" & "@" & _
                        strordering & "@@@@@@" & strbene & "@." & "@" & "@@@@" & "@" & "@@@@@@" & "@" & "@" & "@" & "@@@@@@@@@@@@@@@@@@@@@@@@@@" & _
                        "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@" & strdelmet & "@@@@@@@@@@@@@@@@@@@@@@@"
                        Cells(3, 2) = strTot 'strnetamt1 + Cells(3, 2)
                        
                      Print #2, RplChar(strLine, "^", " ")
                      xcount = 1
                        'If Trim(Mid(data, 99, 1)) <> "" Then
                        Do Until xcount = ctr2
                            invoiceLine = Trim(Mid(myArray(xcount), 99, 25))
                            invoiceLine2 = Trim(Mid(myArray(xcount), 124, 8))
                            invoiceLine3 = Trim(Mid(myArray(xcount), 132, 30))
                            strLine = "INV@" & RplChar(invoiceLine, "'", " ") & "     " & RplChar(invoiceLine2, "'", " ") & "     " & RplChar(invoiceLine3, "'", " ")
                            Print #2, strLine
                            xcount = xcount + 1
                        Loop
            End If
            
        Loop
                    
                      
       Loop
       
                    
            MsgBox "Conversion Complete.  Please upload the target file to Citidirect.", vbInformation + vbOKOnly
            
    
        Close #1
        Close #2
        
        Exit Sub
    ErrorTrap:
        MsgBox "Error : " & Err.Description, vbCritical + vbOKOnly
        Close #1
        Close #2
        
    End Sub
    Here I attached a sample textfile that will be used to upload and convert it to another text file.

    And the password to open the vb code is "1234"
    Attached Files Attached Files
    Last edited by crisshinn; 04-28-2011 at 07:22 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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