tidweb
04-20-2009, 03:35 AM
Hi guys!
I have a problem.
My script functions so:
Reads a file (Results.txt) with different path (\\xp01\c$\test.txt;
\\xp02\c$\test.txt;
etc)
read from ReplaceData.txt values;
The file is with two values for line, a value to find and a value to replace
(this file has different lines).
For examples 12345 cc,123456
654321,123488
852369,523641
etc
The problem is that the script reads only the first line.
I need to the script reads all the value,
but i'm newbie and i don't know how i can do
(i'm think the problem is here:
Dim arrServiceList : arrServiceList = Split(strNextLine, ",")).
Thanks for help.
Regards,
Tidweb
Const cnCol1Start = 1
Const cnColWidth = 25
Dim cnCol2Start : cnCol2Start = cnColWidth + 1
Dim cnCol3Start : cnCol3Start = cnColWidth + cnColWidth + 1
Dim sFillSpaces : sFillSpaces = Space(cnColWidth)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile("C:\Results.txt")
Do Until objFile.AtEndOfStream
Dim objTextFile : Set objTextFile = objFSO.OpenTextFile _ ("c:\ReplaceData.txt")
Do Until objTextFile.AtEndOfStream
Dim strNextLine : strNextLine = objTextFile.Readline
Dim arrServiceList : arrServiceList = Split(strNextLine, ",")
Dim sNeedle : sNeedle = arrServiceList(0)
sNeedle = Left(sNeedle & sFillSpaces, cnColWidth)
Dim sNewCol1 : sNewCol1 = arrServiceList(1)
sNewCol1 = Left(sNewCol1 & sFillSpaces, cnColWidth)
Dim sFSpec : sFSpec = objFSO.GetAbsolutePathName(objFile.ReadLine)
Dim tsIn : Set tsIn = objFSO.OpenTextFile(sFSpec)
Dim tsOut : Set tsOut = objFSO.CreateTextFile(sFSpec & ".out")
Do Until tsIn.AtEndOfStream
Dim sLine : sLine = tsIn.ReadLine
If Mid(sLine, cnCol2Start, cnColWidth) = sNeedle Then
Dim sRpl : sRpl = sNewCol1 & Mid(sLine, cnCol2Start)
If Left(sLine, cnColWidth) = sNeedle Then
sLine = sRpl
Else
Dim sMsg : sMsg = Join(Array(sFSpec & ", Line " & _ tsIn.Line, sLine, "==>", sRpl), vbCrLf)
If vbYes = MsgBox(sMsg, vbYesNo, "Replace?") Then
sLine = sRpl
End If
End If
End If
Loop
tsOut.Write sLine & vbLF
Loop
Loop ' fine lettura path
objTextFile.Close()
objFile.Close()
tsIn.Close
tsOut.Close
Doesn't function!
Regards,
Tidweb
I have a problem.
My script functions so:
Reads a file (Results.txt) with different path (\\xp01\c$\test.txt;
\\xp02\c$\test.txt;
etc)
read from ReplaceData.txt values;
The file is with two values for line, a value to find and a value to replace
(this file has different lines).
For examples 12345 cc,123456
654321,123488
852369,523641
etc
The problem is that the script reads only the first line.
I need to the script reads all the value,
but i'm newbie and i don't know how i can do
(i'm think the problem is here:
Dim arrServiceList : arrServiceList = Split(strNextLine, ",")).
Thanks for help.
Regards,
Tidweb
Const cnCol1Start = 1
Const cnColWidth = 25
Dim cnCol2Start : cnCol2Start = cnColWidth + 1
Dim cnCol3Start : cnCol3Start = cnColWidth + cnColWidth + 1
Dim sFillSpaces : sFillSpaces = Space(cnColWidth)
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile("C:\Results.txt")
Do Until objFile.AtEndOfStream
Dim objTextFile : Set objTextFile = objFSO.OpenTextFile _ ("c:\ReplaceData.txt")
Do Until objTextFile.AtEndOfStream
Dim strNextLine : strNextLine = objTextFile.Readline
Dim arrServiceList : arrServiceList = Split(strNextLine, ",")
Dim sNeedle : sNeedle = arrServiceList(0)
sNeedle = Left(sNeedle & sFillSpaces, cnColWidth)
Dim sNewCol1 : sNewCol1 = arrServiceList(1)
sNewCol1 = Left(sNewCol1 & sFillSpaces, cnColWidth)
Dim sFSpec : sFSpec = objFSO.GetAbsolutePathName(objFile.ReadLine)
Dim tsIn : Set tsIn = objFSO.OpenTextFile(sFSpec)
Dim tsOut : Set tsOut = objFSO.CreateTextFile(sFSpec & ".out")
Do Until tsIn.AtEndOfStream
Dim sLine : sLine = tsIn.ReadLine
If Mid(sLine, cnCol2Start, cnColWidth) = sNeedle Then
Dim sRpl : sRpl = sNewCol1 & Mid(sLine, cnCol2Start)
If Left(sLine, cnColWidth) = sNeedle Then
sLine = sRpl
Else
Dim sMsg : sMsg = Join(Array(sFSpec & ", Line " & _ tsIn.Line, sLine, "==>", sRpl), vbCrLf)
If vbYes = MsgBox(sMsg, vbYesNo, "Replace?") Then
sLine = sRpl
End If
End If
End If
Loop
tsOut.Write sLine & vbLF
Loop
Loop ' fine lettura path
objTextFile.Close()
objFile.Close()
tsIn.Close
tsOut.Close
Doesn't function!
Regards,
Tidweb