
Originally Posted by
_frudo
Thanks for your interest! You can find an example xml file here (2,7 MB ZIP):
Thanks for the source file. The task is really interesting. I had to resort to using Scripting.FileSystemObject, since the source your file has unix line endings (vbLF only)
The presented algorithm works for me not to say that fast. VBA is still a slow language. I have a processing speed of 1000 lines per 6 seconds. That is, 650 thousand will be processed in more than an hour. Frankly speaking, in c# this task would have been completed faster.
But you can always see at what stage of processing the algorithm is (due to Application.StatusBar = "Processing File " & myCounter & " lines processed...").
And you won't need to record the output file, it will be saved automatically.
Sub Duplicate_And_Replace_From_VS()
Dim OutputFileNum As Integer
Dim XmlLine As String
Dim XmlNewLine As String
Dim currentBarStatus As Boolean, myCounter As Long
Dim startTime As Date, endTime As Date
startTime = Now
currentBarStatus = Application.DisplayStatusBar
Application.DisplayStatusBar = True
Dim fso As Scripting.FileSystemObject
Set fso = New Scripting.FileSystemObject
Dim fInputFile As Scripting.TextStream
Set fInputFile = fso.OpenTextFile("arch NOT site 2023-01-14.osm", ForReading, False, TristateMixed)
OutputFileNum = FreeFile()
Open "arch NOT site 2023-01-14New.osm" For Append As #OutputFileNum
While Not fInputFile.AtEndOfStream
XmlLine = fInputFile.ReadLine()
Print #OutputFileNum, XmlLine
myCounter = myCounter + 1
If InStr(1, XmlLine, sTEXT) > 0 Then
XmlNewLine = Replace(XmlLine, sTEXT, sREPLACETEXT)
Print #OutputFileNum, XmlNewLine
End If
Application.StatusBar = "Processing File " & myCounter & " lines processed..."
DoEvents
Wend
fInputFile.Close
Close #OutputFileNum
Application.DisplayStatusBar = currentBarStatus
endTime = Now
Dim elapsedTime As Integer
elapsedTime = DateDiff("s", startTime, endTime)
MsgBox "Done for " & elapsedTime & "sec."
End Sub