November 27, 2006 at 1:46 pm
Hello,
I have a series of fixed width flat files where the character length of each record is 384. The problem is that there is not a carriage return after the ends of some of the records. There is research under way to find out just exactly why this happens, but in the meantime, I need to find a way to discover the occurances of the problem, and insert the carriage return where it needs to go.
Should I try an Active X script to approach the problem, or explore possibilities with a batch file? Is there some other way that would be a better approach?
If you can point me to code resources/sample scripts, that would be greatly appreciated. Otherwise, please share any suggestions you think would be helpful.
Thank you for your help!
CSDunn
November 28, 2006 at 9:16 am
Hi CsDunn
I don't know how to do this in VB-script. But I had a similar problem which I used VB or VBA like this:
Sub Test()
Dim strData As String
Dim Utstrang As String
Dim intFileNo As String
Dim intFileNo2 As String
intFileNo = FreeFile
intFileNo2 = FreeFile + 1
Utstrang = ""
Open "C:\etc\out.txt" For Output As intFileNo2 'Open a file to write to
Open "C:\etc\in.txt" For Input As intFileNo 'Open a file to read from
Do Until EOF(intFileNo)
Do Until Len(Utstrang) = 8 'Replace number with your record len 384
If Not EOF(intFileNo) Then
strData = Input(1, intFileNo)
strData = Replace(strData, Chr(13), "") 'Will replace Cr and Lf if exist with blank
strData = Replace(strData, Chr(10), "")
Utstrang = Utstrang & strData
Else
GoTo Ready
End If
Loop
Utstrang = Utstrang & Cr 'And Cr and or CrLf as record end
Print #intFileNo2, Utstrang
Utstrang = ""
Loop
Ready:
Close #intFileNo
Close #intFileNo2
End Sub
VB is fast so a big file 20Mbyte is "washed" pretty fast.
/Gosta
November 28, 2006 at 9:36 am
I believe you have to use ActiveX. That is the power of DTS.
November 28, 2006 at 12:07 pm
Thanks, I'll try some variation of this.
CSDunn
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply