I am trying to read through a text file and pull out bits of information I need. I have it 1/2 working but need to figure out how to loop through it to get the other 1/2
Sample log file
'--------------------------------------------------------------------------------------------------------------
[01:32:18.281] [@Flos'tok] [@Flos'tok] [Force Valor {875503313485824}] [ApplyEffect {836045448945477}: Force Valor {875503313485824}] ()
[01:32:18.281] [@Flos'tok] [@Flos'tok] [Force Valor {875503313485824}] [ApplyEffect {836045448945477}: Fortification {875503313486158}] ()
[01:32:18.282] [@Flos'tok] [@Flos'tok] [Force Valor {875503313485824}] [ApplyEffect {836045448945477}: Lucky Shots {875503313486145}] ()
[01:32:18.282] [@Flos'tok] [@Flos'tok] [Bio-Enhanced Resolve Stim {1483086567047168}] [ApplyEffect {836045448945477}: Bio-Enhanced Resolve Stim {1483086567047168}] ()
[01:32:18.282] [@Flos'tok] [@Flos'tok] [Safe Login {973870949466112}] [ApplyEffect {836045448945477}: Safe Login Immunity {973870949466372}] ()
[01:32:18.369] [@Flos'tok] [@Flos'tok] [] [Spend {836045448945473}: Force {836045448938502}] (100)
[01:32:18.369] [@Flos'tok] [@Flos'tok] [Combat Technique {979806594269184}] [ApplyEffect {836045448945477}: Combat Technique {979806594269184}] ()
[01:32:18.370] [@Flos'tok] [@Flos'tok] [Sprint {810670782152704}] [ApplyEffect {836045448945477}: Sprint {810670782152704}] ()
[01:32:19.967] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [ {2531161666486272}] [ApplyEffect {836045448945477}: Lucky Shots {2531161666486533}] ()
[01:32:19.967] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [ {2531161666486272}] [ApplyEffect {836045448945477}: Force Valor {2531161666486540}] ()
[01:32:19.968] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [ {2531161666486272}] [ApplyEffect {836045448945477}: Fortification {2531161666486543}] ()
[01:32:22.886] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [Med Scan {2074812801351680}] [Event {836045448945472}: AbilityActivate {836045448945479}] ()
[01:32:24.921] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [Med Scan {2074812801351680}] [ApplyEffect {836045448945477}: Heal {836045448945500}] (606) <45>
[01:32:26.030] [@Flos'tok] [@Flos'tok] [Safe Login {973870949466112}] [RemoveEffect {836045448945478}: Safe Login Immunity {973870949466372}] ()
[01:32:26.031] [@Flos'tok:Tharan Cedrax {493285583880192}] [@Flos'tok:Tharan Cedrax {493285583880192}] [Safe Login {973870949466112}] [RemoveEffect {836045448945478}: Safe Login Immunity {973870949466372}] ()
[01:32:38.426] [@Flos'tok] [@Flos'tok] [Looting {810795336204288}] [Event {836045448945472}: AbilityActivate {836045448945479}] ()
[01:32:59.413] [@Flos'tok] [@Flos'tok] [Deploy Field Repair Droid {2941953813512192}] [Event {836045448945472}: AbilityActivate {836045448945479}] ()
[01:33:00.966] [@Flos'tok] [@Flos'tok] [Deploy Field Repair Droid {2941953813512192}] [ApplyEffect {836045448945477}: Basic Field Repair Droid {2941953813512452}] ()
'----------------------------------------------------------------------------------------------------------------
The code I am using to read a specific line in my log file
'----------------------------------------------------------------------------------------------------------------
Public Shared Function ReadSpecifiedLine(file As String, lineNum As Integer) As String
'create a variable to hold the contents of the file
Dim contents As String = String.Empty
'always use a try...catch to deal
'with any exceptions that may occur
Try
Dim logFileStream As New FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)
Using stream As New StreamReader(logFileStream)
contents = stream.ReadToEnd().Replace(vbCr & vbLf, vbLf).Replace(vbLf & vbCr, vbLf)
Dim linesArray As String() = contents.Split(New Char() {ControlChars.Lf})
'Make sure we have ana ctual array
If linesArray.Length > 1 Then
'Make sure user didnt provide number greater than the number
'of lines in the array, and not less than 0 (zero) Thanks AdamSpeight2008
If Not lineNum > linesArray.Length AndAlso Not lineNum < 0 Then
Return linesArray(lineNum)
Else
'Failed our check so return the first line in the array
Return linesArray(0)
End If
Else
'No array so return the line
Return contents
End If
End Using
Catch Ex As Exception
Return Ex.ToString()
End Try
End Function
'----------------------------------------------------------------------------------------------------------------
And finally my code that 1/2 works
'----------------------------------------------------------------------------------------------------------------
Public Function GetToonName(ByVal WhichToon)
If WhichToon = 1 Then
Dim ToonInfo As String = ReadSpecifiedLine(Label6.Text, 1)
Dim str As String
Dim strArr() As String
Dim count As Integer
str = ToonInfo
strArr = str.Split(New Char() {"]"c})
For count = 0 To strArr.Length - 1
Try
Dim strValue
strValue = Replace(Replace(Regex.Replace(strArr(1), "\{.+?}]*?", ""), "@", ""), "[", "")
Label12.Text = strValue 'debug output
Label17.Text = Label12.Text
If Label7.Text = 0 Then
Label17.Text = "Loading"
End If
Catch Ex As Exception
LogConsole.Text = Ex.Message
End Try
Next
End If
If WhichToon = 2 Then
'this one is funky.
'I need to check for a : and if it doesn't have one, read the next line, and if it doesn't have one the next until it does
'up to line 20 and then give up and list as no companion
Dim ToonInfo As String = ReadSpecifiedLine(Label6.Text, 9 - 1)
Dim str As String
Dim strArr() As String
Dim count As Integer
str = ToonInfo
strArr = str.Split(New Char() {"]"c})
For count = 0 To strArr.Length - 1
Try
LogConsole.Text = strArr(1)
Dim strValue
strValue = Replace(Replace(Regex.Replace(strArr(1), "\{.+?}]*?", ""), "@", ""), "[", "")
Label13.Text = Replace(strValue, Label12.Text + ":", "") 'debug output
Label16.Text = Label13.Text
Catch Ex As Exception
LogConsole.Text = Ex.Message
End Try
Next
End If
' - strAryWords is now an array
Return 0
End Function
'----------------------------------------------------------------------------------------------------------------
The 1st part "If WhichToon = 1 Then" works perfectly as the 1st line of code always has what I look for
thee 2nd part "If WhichToon = 2 Then" Doesn't
Right now I have it set to look at the 2nd line for toonname:companionname but it might be in the 3 or the 20th line [or anywhere in between, or not at all if there is no companion]
I've used things like If strArr(1).Contains(":") Then and it can see it [or not] depending on which line I manually tell it to look at and I have run it through a loop such as
IF NOT strArr(1).Contains(":") Then
Dim i
For i = 0 to 20
ToonInfo = ReadSpecifiedLine(Label6.Text, i)
next
which does loop through it and I can see the output in my debug field but I can't "trap" it when it does find it.
Any ideas on how I might be able to do this in real basic methods?