看板 Programming
作者 linnet1616 (新使用者)
標題 vbs 螢幕輸出轉成txt檔案輸出格式不一致是否可以幫我看一下程式要如何修改
時間 2019-12-31 Tue. 21:59:00




上圖為程式在螢幕輸出結果


輸出成txt檔案時格式與螢幕輸出結果不一致

下述為程式
Set objRegEx = CreateObject("VBScript.RegExp")
Dim arrFileLines()
AAA = ""
i = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("d:\input.txt", 1)
Do Until objFile.AtEndOfStream
Redim Preserve arrFileLines(i)
arrFileLines(i) = objFile.ReadLine
i = i + 1
Loop
objFile.Close

Set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Pattern = "\d{5}"
For l =  LBound(arrFileLines) to UBound(arrFileLines)
if l <10 then
strNewString = objRegEx.Replace(arrFileLines(l),"0000" & (l+1) )
AAA = AAA & strNewString & chr(10)
else
strNewString = objRegEx.Replace(arrFileLines(l),"000" & (l+1) )
AAA = AAA & strNewString & chr(10)
end if
next

Wscript.Echo AAA
Dim fso, MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("d:\outfile.txt", True)
MyFile.WriteLine(AAA)
MyFile.Close

--
※ 作者: linnet1616 時間: 2019-12-31 21:59:00 (台灣)
※ 編輯: linnet1616 時間: 2019-12-31 21:59:53 (台灣)