Not sure if this is the right spot for this question but I'm here!
I'm trying to make a vb script that opens large text files, one at time, searches each line for Null values (there can be many) and then replaces them with a space. My coworker put the following together which takes a very long time because it is basically iterating through millions of characters in the file:
Do Until objFile.AtEndOfStream
strCharacters = objFile.Read(1)
'Wscript.Echo strCharacters
' Wscript.Echo Asc(strCharacters)
If Asc(strCharacters) = 0 Then
objOutFile.Write(" ")
Else
objOutFile.Write(strCharacters)
End If
Loop
What I was hoping to do was read each line and perform the Replace function if there is an ASCII value of 0 but I keep getting an error with:
Do Until objFile.AtEndOfStream
strCharacters = objFile.ReadLine
newStrCharacters = Replace(strCharacters,Chr(Asc(0))," ")
'Wscript.Echo strCharacters
'Wscript.Echo newStrCharacters
objOutFile.Write(newStrCharacters)
Loop
However I get prompted with an Invalid Call or Argument throw and I don't understand why? Both variables in my loop, before and after (strCharacters & newStrCharacters) display correctly, I just can't seem to write to the file, which looks like:
strTemp = "C:\Documents and Settings\...\SpecialCharRemoval\out1.txt"
Set objOutFile = objFSO.CreateTextFile(strTemp,True)
Can someone please nudge me in the right direction?