Vbscript 试图在文本文档中插入分隔符

Vbscript 试图在文本文档中插入分隔符,vbscript,Vbscript,我试图在文本文件的每一行的某些点上放置一个垂直条。我的代码非常简单,我很确定……但当我尝试运行它时,什么都没有发生。我连一个错误都没有。它应该写入的文件仍然是一个空白文本文件 Const ForReading = 1 Const ForWriting = 2 arrCommas = Array(10,14,21,24,39,43,46,61,72,79,82,85,88,91,94,97,101,142,173,189,192,198,205,211,218,222,229,236,240)

我试图在文本文件的每一行的某些点上放置一个垂直条。我的代码非常简单,我很确定……但当我尝试运行它时,什么都没有发生。我连一个错误都没有。它应该写入的文件仍然是一个空白文本文件

Const ForReading = 1
Const ForWriting = 2

arrCommas =  Array(10,14,21,24,39,43,46,61,72,79,82,85,88,91,94,97,101,142,173,189,192,198,205,211,218,222,229,236,240)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsedited\mbsfact102013_linebreaks.txt", ForReading)

Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
intLength = Len(strLine)
For Each strComma in arrCommas
    strLine = Left(strLine, strComma - 1) + "|" + Mid(strLine, strComma, intLength)
Next
strText = strText & strLine & vbCrLf
Loop

objFile.Close

Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsfinal\mbsfact102013_delimited.txt", ForWriting)
objFile.Write strText
objFile.Close

除此之外,每次插入逗号时,该移位后的所有索引都会减少一个。在构造
arrcoma
s时,您是否考虑到了这一点?我还将打开输出文件,并在处理完成后立即写入行。如果输入文件很大,您将使用比所需更多的内存。也就是说,这怎么不符合你的要求呢?你有错误吗?意外的结果。。。请更具体一点。它应该写入的文件仍然是空的。另外,我认为放置在do循环中的strComma-1将转换为accountCode对我来说是可行的。您的代码是否可能包含未显示的“下一步继续时出错时的
?因为这会掩盖你所遇到的任何错误(比如无法创建一个不存在的输出文件)。我不知道这是否有帮助,但它在之前工作过一次,垂直条在错误的位置,所以我只是更改了逗号中的值。重新保存并再次运行后,没有结果。如果您使用cscript.exe解析vbs文件,请尝试在
wscript.echo
行中显示
strLine
在For循环之前和内部的内容。-1用于将strText合并到strText并将strText文件写入输出文件。您知道可以编辑文章,而不仅仅是对其进行向下投票,对的
Const ForReading = 1
Const ForWriting = 2

arrCommas =  Array(10,14,21,24,39,43,46,61,72,79,82,85,88,91,94,97,101,142,173,189,192,198,205,211,218,222,229,236,240)

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsedited\mbsfact102013_linebreaks.txt", ForReading)

strTextFile = objFile.ReadAll
objFile.Close

aTextFile = Split(strTextFile, vbCRLF)

strText = ""
For Each strLine In aTextFile
    intLength = Len(strLine)
    For Each strComma in arrCommas
        strLine = Left(strLine, strComma - 1) + "|" + Mid(strLine, strComma, intLength)
    Next
    strText = strText & strLine & vbCrLf
Next

Set objFile = objFSO.OpenTextFile("c:\SQL DATA FILES\MBS Stats\mbsfinal\mbsfact102013_delimited.txt", ForWriting)
objFile.Write strText
objFile.Close