Sub ReadChars()
Dim strCharacters(20000000) As String * 1
Dim intCharcount, intMaxChars As Long
Dim booIsQuote As Boolean
Dim i, j As Long
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objfile = objFSO.opentextfile("x:\TCB\Purchasing\08-09\ERP\Data Conversion\o_bp-inspect.txt", 1)
'Input File
intCharcount = 0
strSentence = ""
Do Until objfile.AtEndOfStream
strCharacters(intCharcount) = objfile.read(1)
intCharcount = intCharcount + 1
Loop
objfile.Close
'Remove Double Quotes in Text areas, there are a few spurious instances
i = 0
strPattern = "|" & Chr$(34) & Chr$(34) & "|"
Do Until i = intCharcount - 1
If strCharacters(i) & strCharacters(i + 1) & strCharacters(i + 2) & strCharacters(i + 3) <> strPattern Then GoTo Skip1
strCharacters(i + 1) = Chr$(0)
strCharacters(i + 2) = Chr$(0)
i = i + 2
Skip1:
i = i + 1
Loop
'Remove CR/LF between quotes
i = 0
j = 0
Do Until i = intCharcount - 1
If strCharacters(i) = Chr$(34) Then
booIsQuote = Not booIsQuote
GoTo skip
End If
If (strCharacters(i) = Chr$(10) Or strCharacters(i) = Chr$(13)) And booIsQuote Then
strCharacters(i) = " "
End If
skip:
i = i + 1
Loop
'Write Array to file
Set outfso = CreateObject("Scripting.FileSystemObject")
Set outfile = outfso.createtextfile("x:\TCB\Purchasing\08-09\ERP\Data Conversion\o_bp-inspect1.txt", True)
i = 0
Do Until i = intCharcount - 1
outfile.write (strCharacters(i))
i = i + 1
Loop
outfile.Close
End Sub
|