Hi,
This question is asked at a tail end of another thread regarding reading from a file, so I thought I'd start a new thread regarding this specific question.
I have the following that is reading the lines of a file into the Array: -
Now that the Array has been populated, I'd like to start from the bottom/end of the array and work up to look for a line from the file imported that contains "System:"
Here is a sample of such a line from the file: -
19:47:31} System:11(Blau Aescs PM-L b37-11) Body:0 Pos1.13764e+010,7.24941e+009,-7.96476e+009) cruising
If such a line is found I then need to grab just "Blau Aescs PM-L b37-11" from it.
I don't want to start from the top as I'm always only interested in the last entry in the file of such a line, of which there will be many, the test file I'm working with currently has over 5,000 lines in it and some others over 9,000.
In VB.Net I was able to use: -
As per this snippet of code: -
However, unfortunately this isn't available within VBA, hence trying to find another way around it.
Does anyone know how this can be done, or an alternative to achieve the result I'm after?
Thanks in advance.
Regards
This question is asked at a tail end of another thread regarding reading from a file, so I thought I'd start a new thread regarding this specific question.
I have the following that is reading the lines of a file into the Array: -
Code:
Sub ReadStrangeFile()
' Requires a reference to Microsoft Scripting Runtime (Tools > References)
Dim FSO As FileSystemObject
Dim FSOFile As File
Dim FSOStream As TextStream
Dim arrFileLines() As String
Dim i As Integer
Set FSO = New FileSystemObject
Set FSOFile = FSO.GetFile(strLogFile)
Set FSOStream = FSOFile.OpenAsTextStream(ForReading, TristateUseDefault)
i = 0
Do While Not FSOStream.AtEndOfStream
ReDim Preserve arrFileLines(i)
arrFileLines(i) = FSOStream.ReadLine
i = i + 1
Loop
FSOStream.Close
Debug.Print UBound(arrFileLines())
End Sub
Now that the Array has been populated, I'd like to start from the bottom/end of the array and work up to look for a line from the file imported that contains "System:"
Here is a sample of such a line from the file: -
19:47:31} System:11(Blau Aescs PM-L b37-11) Body:0 Pos1.13764e+010,7.24941e+009,-7.96476e+009) cruising
If such a line is found I then need to grab just "Blau Aescs PM-L b37-11" from it.
I don't want to start from the top as I'm always only interested in the last entry in the file of such a line, of which there will be many, the test file I'm working with currently has over 5,000 lines in it and some others over 9,000.
In VB.Net I was able to use: -
Code:
Array.Reverse()
As per this snippet of code: -
Code:
strLines.Reverse()
For Each strLine In strLines
strTextLine = strLine
If strTextLine.Contains("System:") Then
intFirstPos = InStr(1, strTextLine, "(", CompareMethod.Text)
intLastPos = InStr(1, strTextLine, ")", CompareMethod.Text)
intLength = intLastPos - intFirstPos
strCurrSystem = Mid(strTextLine, intFirstPos + 1, intLength - 1)
Exit For
End If
Next
However, unfortunately this isn't available within VBA, hence trying to find another way around it.
Does anyone know how this can be done, or an alternative to achieve the result I'm after?
Thanks in advance.
Regards