Format length of invoices in a textfile

espenzaal

New member
Local time
Today, 23:48
Joined
Mar 1, 2006
Messages
6
Hello!
I'm one of the less skilled people in vba to say the least. I am here because i need som help with this code (see below). I have one other code that is running first which is replacing some characters in the file. That code has an input and an output file.
The code below is taking the output file from the previous job and are supposed to make each invoice 68 lines. The code im showing here was made by one guy that we had rented to do this job but he is not in our service anymore so i would like some help to make this work.
Here is the code.

lFreefile = FreeFile

filename = "C:\Ross\code\bids\norsk it\ts.txt"
' The file length we require
FileLength = 68

Open filename For Input As #lFreefile
MyFile = Input$(LOF(lFreefile), lFreefile) 'Assigns The Text In The
' File To MyFileText
Close #lFreefile


' This loop has been designed to lopp through each invoice ("Faktura 1" to "Faktura 1")
' and count the number of chr(10)'s. These character dictate the
' length of each invoice and so adding or deleting them will let
' us dictate the size

For i = 1 To Len(MyFile)
start_text = Mid(MyFile, i, 12)
If start_text = "Faktura 1" Then
counter = i + 1
Do Until end_text = "Faktura 1"
character = Mid(MyFile, counter, 1)
On Error GoTo skipper ' The only time this will error is at the EOF
result = Asc(character)
end_text = Mid(MyFile, counter, 12)

If result = 10 Then
return_count = return_count + 1
End If
counter = counter + 1
Loop

' count the amount of invoices, doesn't effect code
invoices = invoices + 1

' either expand or delete the number of chr(10)'s
If return_count <> FileLength Then
Do Until return_count = FileLength
If return_count < FileLength Then
MyFile = Mid(MyFile, 1, counter - 48) & Chr(10) & Mid(MyFile, counter - 47)
return_count = return_count + 1
ElseIf return_count > FileLength Then
'not tested, if the below character has an ascii value of 10
'then its perfect
character = Asc(Mid(MyFile, counter - 47, 1))
MyFile = Mid(MyFile, 1, counter - 48) & Mid(MyFile, counter - 46)
return_count = return_count - 1
End If
Loop
End If

end_text = 0
return_count = 0
i = counter

End If
Next i


skipper:

Open "c:\myfile.txt" For Output As #6
Print #6, MyFile
Close #6

================================================== ======

This code he made for another of our projects but i cant make it work in this new mdb i got now. Im not used to post threads regarding vba questions also so if i have missed something or if you have any questions please reply

Espen
 

Users who are viewing this thread

Back
Top Bottom