I am not a vb programmer. I dabble in vba. This script was inherited from a former co-worker.
What I need this script to do is replace all pipe (|) characters in the 71st column only, to a dash (-).
Right now, the code is not doing that, but it is adding a double quote comma and double quote (",") at the end of every line.
Here is the code:
I have been looking some of this stuff up online, but I am not understanding where in the code it is adding that stupid "," at the end of the file, and why it is not replacing | with - es.
Any help would be greatly appreciated!
Thank you,
misscrf
It is never too late to become what you could have been ~ George Eliot
What I need this script to do is replace all pipe (|) characters in the 71st column only, to a dash (-).
Right now, the code is not doing that, but it is adding a double quote comma and double quote (",") at the end of every line.
Here is the code:
Code:
Const ForAppending = 8
Const ForReading = 1
strFileName = InputBox("Enter IDX Filename: ")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile (strFileName, ForReading)
intPos = InStr(1,strFileName,".",1)
strFileName = Left(strFileName,(intPos-1))
Set objTextFile2 = objFSO.OpenTextFile (strFileName & "-Cleaned_SC.idx", ForAppending, True)
linenumber = 1
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrServiceList = Split(strNextLine , Chr(34) & "," & Chr(34))
If linenumber > 0 Then
For i = 0 to Ubound(arrServiceList)
If i <= Ubound(arrServiceList) Then
If (i = 71) Then
strTemp = Replace(arrServiceList(i), "|", "-")
objTextFile2.Write(strTemp&Chr(34)&","&Chr(34))
ElseIf (i = 95) Then
strTemp = Replace(arrServiceList(i), ",", "|")
objTextFile2.Write(strTemp)
ElseIf (i = 20) Or (i = 22) or (i = 26)Or (i = 64) Then
strTemp = Replace(arrServiceList(i), ",", "|")
objTextFile2.Write(strTemp&Chr(34)&","&Chr(34))
Else
objTextFile2.Write(arrServiceList(i)&Chr(34)&","&Chr(34))
End If
End If
Next
objTextFile2.Write(vbCrLf)
End if
linenumber = linenumber + 1
Loop
objTextFile.Close
objTextFile2.Close
MsgBox "Replace Pipes script is finished running."
I have been looking some of this stuff up online, but I am not understanding where in the code it is adding that stupid "," at the end of the file, and why it is not replacing | with - es.
Any help would be greatly appreciated!
Thank you,
misscrf
It is never too late to become what you could have been ~ George Eliot