Hello VBS Gurus,
I've an easy challenge for you
I'm working on a text file, the Data comes in 2 lines, but some lines has "FORM FEEDER", doing the following code to replace the form feeder by a new line
and then split the contents so I can merge the 2 lines
the results:
It removes and adds a new line but doesn't split correctly the output !! still in 2 lines.
Any Idea? what I'm doing wrong?
Sample data in .txt is here
and here's my mighty nighty script..
--------------------------------------------
Const ForReading = 1
Const ForWriting = 2
strSourceTxtFile = "PXDRAD January 2010 thru May 2010.txt"
strTargetTxtFile = "PXDRAD January 2010 thru May 2010 - One Line - " & ShortDateTime(Now) & ".txt"
'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strSourceTxtFile, ForReading)
'Skip header data
For x = 0 to 19
objFile.ReadLine
Next
strAllLines = objFile.ReadAll
objFile.Close
arrAllLines = Split(strAllLines, vbFormFeed)
For i = 0 TO UBound(arrAllLines) - 1 Step 2
strNewText = strNewText & arrAllLines(i) & arrAllLines(i + 1) & VbCrLf
Next
Set objFile = objFSO.OpenTextFile(strTargetTxtFile, ForWriting, True)
objFile.WriteLine(strNewText)
objFile.Close
Function ShortDateTime(dtmTime)
strYear = Year(dtmTime)
strMonth = Right("0" & Month(dtmTime), 2)
strDay = Right("0" & Day(dtmTime), 2)
strHour = Right("0" & Hour(dtmTime), 2)
strMinute = Right("0" & Minute(dtmTime), 2)
strSecond = Right("0" & Second(dtmTime), 2)
ShortDateTime = strYear & strMonth & strDay & "-" & strHour & strMinute & strSecond
End Function
-------------------------------------------------
Thanks
I've an easy challenge for you
I'm working on a text file, the Data comes in 2 lines, but some lines has "FORM FEEDER", doing the following code to replace the form feeder by a new line
and then split the contents so I can merge the 2 lines
the results:
It removes and adds a new line but doesn't split correctly the output !! still in 2 lines.
Any Idea? what I'm doing wrong?
Sample data in .txt is here
and here's my mighty nighty script..
--------------------------------------------
Const ForReading = 1
Const ForWriting = 2
strSourceTxtFile = "PXDRAD January 2010 thru May 2010.txt"
strTargetTxtFile = "PXDRAD January 2010 thru May 2010 - One Line - " & ShortDateTime(Now) & ".txt"
'Reads the TXT file
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strSourceTxtFile, ForReading)
'Skip header data
For x = 0 to 19
objFile.ReadLine
Next
strAllLines = objFile.ReadAll
objFile.Close
arrAllLines = Split(strAllLines, vbFormFeed)
For i = 0 TO UBound(arrAllLines) - 1 Step 2
strNewText = strNewText & arrAllLines(i) & arrAllLines(i + 1) & VbCrLf
Next
Set objFile = objFSO.OpenTextFile(strTargetTxtFile, ForWriting, True)
objFile.WriteLine(strNewText)
objFile.Close
Function ShortDateTime(dtmTime)
strYear = Year(dtmTime)
strMonth = Right("0" & Month(dtmTime), 2)
strDay = Right("0" & Day(dtmTime), 2)
strHour = Right("0" & Hour(dtmTime), 2)
strMinute = Right("0" & Minute(dtmTime), 2)
strSecond = Right("0" & Second(dtmTime), 2)
ShortDateTime = strYear & strMonth & strDay & "-" & strHour & strMinute & strSecond
End Function
-------------------------------------------------
Thanks