Ok being a nice guy, I will write you some simple code to parse a file and grab out variables. I can help you massage that code to work with your stuff, hopefully along the way you learn from what I have done.
Is this data tab delimited or just space delimited? Do you have access to change the way this log file is pumped out? Might be easier if you separate the data by commas. I am going to make the output file delimited by commas and call it a .csv so you can open it in excel.
I split each line down into pieces by "breaking" it on the space character. The String.Split() command will break a string into an array of string, its a very useful command when working with Log File data.
On the form I put one button and left it with the default name. I copied the data you gave me and pasted it to a text file named Test1.txt and put it in my C root directory. Then I told my subroutine to save it as a file called test2.csv (located in C root as well). You can open in Notepad, or preferably Excel.
If you copy and paste this code into a Form with 1 button (default name) it should work.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
parseFile("c:\test1.txt", "c:\test2.csv")
End Sub
Public Sub parseFile(ByVal FileName As String, ByVal NewFileName As String)
'FileName = the file to be parsed
'NewFileName is the new file with filtered results
'We could filter the results and display them in
'a view with windows controls if you wanted that instead
Dim FF As Integer = FreeFile() 'This returns an integer value to designate for file open and close
Dim sLine As String = "" 'This is a temporary var to suck each line in
Dim newFile As String = "" 'Holds the new file's data
Try 'Use a try-catch (exception handling) incase any errors occur
FileOpen(FF, FileName, OpenMode.Input) 'Open FileName for reading
Do While Not EOF(FF) 'EOF returns a True or False based on if we hit the End of File
sLine = LineInput(FF) 'This grabs the entire line into a string variable
Dim LineData() As String = sLine.Split(" ") 'This returns an array of strings tokenized by the space
'LineData(0) should be the Date
'LineData(1) should be the Time
'LineData(2) should say TEAMS, JOIN, GRIEF, or KILL
'LineData(3) should say JOIN, SUCCESS, ADDED, or a playername if it was KILL
'LineData(4) should be a playername or the word player
'You can see that the logic sort of branches here based on LineData(2)
'So lets dig into this array and get our data out!
'Firstly, we have to make sure LineData.Length > 1
'and that isNothing(LineData) returns False so we don't error
If Not IsNothing(LineData) AndAlso LineData.Length > 1 Then
Select Case Trim(LineData(2))
'this is an advanced If statement basically
'trim() removes spaces from the ends of string
'It seems to me that we are only interested in the case
'where LineData(2) = JOIN so that is the only place
'I will write code
Case "TEAMS"
'LineData(2) = TEAMS
Case "JOIN"
'LineData(2) = JOIN
'we know LineData(4) will have playername here
newFile &= LineData(4).Trim("""") 'This trims a " from the ends of a string.
newFile &= "," & LineData(9).Trim("(").Trim(")") 'This trims a ( from both sides, then a ) from both sides
newFile &= vbNewLine 'Creates a carrage return
'Note that &= is like saying newFile = newFile & ","... etc
Case "GRIEF"
'LineData(2) = GRIEF
Case "KILL"
'LineData(2) = KILL
End Select
Else
'Blank Line Do Nothing
End If
Loop
Catch ex As Exception
'Darn something happenned, this will give you some idea:
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error Occurred")
Finally
'The loop is done or an error occurred
'Lets close that file in all cases (Finally gets called after the Try code and Catch code
FileClose(FF)
End Try
FF = FreeFile() 'Reset FF incase the last value is no longer available to us
Try
'This is in a seperate try block incase the last one errors
'we can then atleast get out the data already parsed
FileOpen(FF, NewFileName, OpenMode.Output) 'Open newFileName for output
PrintLine(FF, newFile) 'easiest thing
FileClose(FF)
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.OkOnly, "Error Occurred")
End Try
MsgBox("Success!", MsgBoxStyle.OkOnly, "Yea, Praise be to Sean")
End Sub
Happy Coding!!!
Firesickle.com