PS: The speed of vbs should be quite fast... I don't have specific data, you can test it yourself.
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!
Const ForReading = 1 'Set the text opening mode to read
Const ForWriting = 2 'Set the text opening mode to write
Const ForAppending = 8 'Set the text opening mode to append
Const InFile = "a.txt" 'Set the text to open
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, which is needed for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in read mode
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it's not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - Len(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr = OutStr & OutLine & vbCrLf
i = i + 1
Sum= Sum+ CLng(NeedData(2))
End If
Loop
OutStr = OutStr & "14080005020214080100112003624143" & AddZero(i,6)
OutStr = OutStr & "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close 'Close the file object
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) 'Open OutFile in write mode
objFile.Write OutStr
objFile.Close 'Close the file object
Set objFile = Nothing
Set objFSO = Nothing
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
Const ForReading = 1 'Set the text opening method to reading
Const ForWriting = 2 'Set the text opening method to writing
Const ForAppending = 8 'Set the text opening method to appending
Const InFile = "a.txt" 'Set the text to open
Dim i,Sum
Dim StrLine,OutStr
i = 1:Sum = 0
'On Error Resume Next
Set objFSO = CreateObject("Scripting.FileSystemObject") 'Reference the FSO object, needed for reading and writing files
Set objFile = objFSO.OpenTextFile(InFile, ForReading) 'Open InFile in reading mode
Do Until objFile.AtEndOfStream
StrLine = objFile.ReadLine 'Read a line
If Len(StrLine) Then 'If it's not an empty line
StrLine = FixStr(StrLine)
NeedData = Split(StrLine," ")
If Right(NeedData(1),1) = "*" Then NeedData(1) = Left(NeedData(1),Len(NeedData(1)) - 1)
NeedData(4) = NeedData(4) & Space(53 - MixLen(NeedData(4)))
OutLine = "2140800050202" & NeedData(1) & "3" & AddZero(i,6) & "00" & NeedData(2)
OutLine = OutLine & "000000000000000011 " & AddZero(i - 1,9) & NeedData(4)
OutStr &= OutLine & vbCrLf
i += 1
Sum += CLng(NeedData(2))
End If
Loop
OutStr &= "14080005020214080100112003624143" & AddZero(i,6)
OutStr &= "00" & AddZero(Sum,15) & "0000000" & AddZero(i - 1,9) & "2" & Space(82)
objFile.Close 'Close the file object
OutFile = "140820" & FormatDate(Date) & "001.txt"
Set objFile = objFSO.OpenTextFile(OutFile, ForWriting,True) 'Open OutFile in writing mode
objFile.Write OutStr
objFile.Close 'Close the file object
Set objFile = Nothing
Set objFSO = Nothing
Function AddZero(sNum,iLen)
Addzero = Right("000000000" & sNum,iLen)
End Function
Function FixStr(StrExp)
Do While InStr(StrExp," ")
StrExp = Replace(StrExp," "," ")
Loop
FixStr = StrExp
End Function
Function MixLen(StrExp)
Dim i,c
For i = 1 /color]To Len(StrExp)
c= Asc(Mid(StrExp, i, 1))
If Not (C /color]>= 0 /color]And C /color]< 128) Then MixLen /color]= MixLen /color]+ 1
MixLen /color]= MixLen /color]+ 1
Next
End Function
Function FormatDate(tDate)
FormatDate = Right(Year(tDate),2) & AddZero(Month(tDate),2) & AddZero(Day(tDate),2)
End Function