|
|
Построчное чтение (FSO) - C записью строк в массив
Private Sub Test001()
Dim sVal$
sVal = CurrentProject.Path & "\Sample.txt"
ParseOneFile sVal
End Sub
Private Sub ParseOneFile(sFilePath)
Dim FSO As Object
Dim FSOFile As Object
Dim TextStream As Object
Dim FileLines() As String
Dim LineValues() As String
Dim lVal As Long, sVal As String
Dim iVal%, lPos As Long
On Error GoTo ParseOneFile_Err
Set FSO = CreateObject("Scripting.FileSystemObject")
Set FSOFile = FSO.GetFile(sFilePath)
Set TextStream = FSOFile.OpenAsTextStream(1)
Do While Not TextStream.AtEndOfStream
sVal = sVal & TextStream.ReadLine & vbNewLine
Loop
TextStream.Close
FileLines = Split(sVal, vbNewLine, -1, vbTextCompare)
For lVal = LBound(FileLines) To UBound(FileLines)
Debug.Print Format(lVal, "000000") & " = " & FileLines(lVal)
LineValues() = Split(FileLines(5), "|")
For iVal = LBound(LineValues) To UBound(LineValues)
Debug.Print iVal & " = " & LineValues(iVal)
Next iVal
Next lVal
ParseOneFile_End:
On Error Resume Next
Set FSO = Nothing
Set FSOFile = Nothing
Set TextStream = Nothing
Err.Clear
Exit Sub
ParseOneFile_Err:
MsgBox "Error " & Err.Number & " (" & Err.Description & ") in Sub : " & _
"ParseOneFile - modParseOrders.", vbCritical, "Error!"
Err.Clear
Resume ParseOneFile_End
End Sub
|
|