Newbee help with data from Text

houdini_pax

New member
Joined
Oct 13, 2005
Messages
1
Programming Experience
Beginner
First off would Like to say what a nice site a lot of good info in here.


Ok trying to learn VB reading the books and forums. I know how to read text files but not sure how to sum the data up and display the data.

Want to display how many Tries were made or tackles

Ok here is where I am at now.

Txt File:

01/07:13:15 HOME "Mark"(8Man) try team RED "5m" by kick
01/07:13:25 HOME "Mike"(Lock) tackle team RED "stop" by blue
01/07:13:35 HOME "Mark"(8Man) try team RED "5m" by kick
01/07:13:45 HOME "Mike"(Lock) tackle team RED "stop" by blue
01/07:13:55 HOME "Mark"(8Man) tackle team RED "5m" by kick
01/07:14:05 HOME "Mike"(Lock) tackle team RED "stop" by blue

etc


Code I have:
Code:
VB.NET:
[SIZE=2][COLOR=#0000ff] Private[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Get_Stats_Click([/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2][COLOR=#000000] sender [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.Object, [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2][COLOR=#000000] e [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#000000] System.EventArgs) [/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2][COLOR=#000000] Get_Stats.Click[/COLOR]
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] input [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2]input = [/SIZE][SIZE=2][COLOR=#0000ff]My[/COLOR][/SIZE][SIZE=2].Computer.FileSystem.ReadAllText([/SIZE][SIZE=2][COLOR=#800000]"D:\Program Files\Ubisoft\Eagle Dynamics\Lock On\Temp\mp_log.txt"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] fileException [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Exception
[/SIZE][SIZE=2][COLOR=#0000ff]Throw[/COLOR][/SIZE][SIZE=2] fileException
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] pat [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2] = [/SIZE][SIZE=2][COLOR=#800000]"(?<pilot>\x22+\w*\x22+\(*\S+\)?).*(?<kill>kill)"
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' Compile the regular expression.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] r [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Regex(pat, RegexOptions.None)
[/SIZE][SIZE=2][COLOR=#008000]' Match the regular expression pattern against a text string.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] m [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Match = r.Match(input)
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] m.Success
[/SIZE][SIZE=2][COLOR=#008000]' Display Group1 and its capture set.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] g2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Group = m.Groups(2)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] g1 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Group = m.Groups(1)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myHT [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] Hashtable()
myHT.Add([/SIZE][SIZE=2][COLOR=#800000]"Pilot"[/COLOR][/SIZE][SIZE=2], g1.ToString())
myHT.Add([/SIZE][SIZE=2][COLOR=#800000]"Kills"[/COLOR][/SIZE][SIZE=2], g2.ToString())
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] dict(myHT.Count - 1) [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] _
System.Collections.DictionaryEntry
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] item [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Collections.DictionaryEntry
myHT.CopyTo(dict, 0)
[/SIZE][SIZE=2][COLOR=#008000]' Iterate dictionary
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] item [/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] dict
[/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2]System.Console.WriteLine( _
Microsoft.VisualBasic.Strings.UCase([/SIZE][SIZE=2][COLOR=#0000ff]CStr[/COLOR][/SIZE][SIZE=2]( _
item.Key)) & [/SIZE][SIZE=2][COLOR=#800000]": "[/COLOR][/SIZE][SIZE=2] & [/SIZE][SIZE=2][COLOR=#0000ff]CStr[/COLOR][/SIZE][SIZE=2](item.Value))
Console.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"Stats"[/COLOR][/SIZE][SIZE=2])
Console.WriteLine(ControlChars.Tab + [/SIZE][SIZE=2][COLOR=#800000]"Count: {0}"[/COLOR][/SIZE][SIZE=2], myHT.Count)
PrintKeysAndValues(myHT)
[/SIZE][SIZE=2][COLOR=#008000]' Advance to the next match.
[/COLOR][/SIZE][SIZE=2]m = m.NextMatch
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Shared[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] PrintKeysAndValues([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] myList [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] Hashtable)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] myEnumerator [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] IDictionaryEnumerator = myList.GetEnumerator()
Console.WriteLine(ControlChars.Tab + [/SIZE][SIZE=2][COLOR=#800000]"-KEY-"[/COLOR][/SIZE][SIZE=2] + ControlChars.Tab _
+ [/SIZE][SIZE=2][COLOR=#800000]"-VALUE-"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]While[/COLOR][/SIZE][SIZE=2] myEnumerator.MoveNext()
Console.WriteLine(ControlChars.Tab + [/SIZE][SIZE=2][COLOR=#800000]"{0}:"[/COLOR][/SIZE][SIZE=2] + ControlChars.Tab _
+ [/SIZE][SIZE=2][COLOR=#800000]"{1}"[/COLOR][/SIZE][SIZE=2], myEnumerator.Key, myEnumerator.Value)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2]Console.WriteLine()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Sub
[/COLOR][/SIZE]



Outputs:

Players:"Mike"(Lock)tackle:tackle
Players:"Mike"(Lock)tackle:tackle
Players:"Mark"(8Man)tackle:tackle
Players:"Mike"(Lock)tackle:tackle


Where I am trying to get but just can't get there.

Players:"Mike"(Lock) tackle:3
Players:"Mark"(8Man)tackle:1

I'm I going in the wrong Direction?

Can I Get There From Here?

Not looking for someone to write the code for me just point me where I can read or samples about it to help me understand how it is done. I can't change the format of the text file do to that the format given to us.

Keep in mind I am a Rugby Player/Pilot To Many hits in the hit so can be slow at times .


Pulling the last Of my gray hairs out on this BTW thanks for the inputs so far have learned alot about Regular Expressions.

Thanks For your help

Mike
 
Back
Top