Imports System.IO
Imports System.Text.Encoding
Imports System.Text.RegularExpressions
Public Class Form1
Private Sub ExitToolStripMenuItem_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
Me.Close()
End Sub
Private strSourcePath As String
Dim ipassinfo As New SortedList
Public Structure user
'Declare data members
Public username As String
Public department As String
Public domestictotal As Decimal
End Structure
Dim userinfo As New user
Private Sub OpenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OpenToolStripMenuItem.Click
Tb_totals.Clear()
tb_usertotals.Clear()
tb_linesproccessed.Clear()
With Me.OpenFileDialog1
.InitialDirectory = "C:\"
' The file could be of any type. The Filter is restricted to Text Format
' files only for demonstration purposes.
.Filter = "Tab delmited (*.csv)|*.csv"
.FilterIndex = 1
' The OpenFileDialog control only has an Open button, not an OK button.
' However, there is no DialogResult.Open enum so use DialogResult.OK.
If .ShowDialog() = Windows.Forms.DialogResult.OK Then
strSourcePath = .FileName
Dim datipass As New StreamReader(.FileName)
'*'' Dim totalChargeByName As New SortedList
Dim fields As String()
Dim count As Int16
Do Until datipass.Peek() = -1
Dim MyLine As String = datipass.ReadLine
Dim myparse As String
'create variable for "'"
myparse = (ControlChars.Quote & "," & ControlChars.Quote)
'Replace "," with tab's
MyLine = MyLine.Replace(myparse, ControlChars.Tab)
'remove certian words
MyLine = MyLine.Replace("usatoday\", "")
MyLine = MyLine.Replace("eu\", "")
'forces everythign to lower
MyLine = MyLine.ToLower
'break feild up on tabs
fields = MyLine.Split(ControlChars.Tab) 'Or Convert.ToChar(Keys.Tab)
'check to see if entrie already exists if not create it
If ipassinfo(fields(2)) Is Nothing Then
'loading the structure
userinfo.username = fields(2)
userinfo.department = "???"
userinfo.domestictotal = fields(9)
'adding the structure to the sortedlist under key username
ipassinfo.Add((fields(2)), userinfo)
Else
' adds charges to total if allready exists
userinfo.domestictotal = userinfo.domestictotal + fields(9)
End If
count = count + 1
Loop
Me.tb_linesproccessed.Text = count
'release the access of the file
datipass.Close()
Dim x As String
Dim y As Decimal
Dim total As Decimal
Dim i As Integer
For i = 0 To ipassinfo.Count - 1
x = ipassinfo.GetKey(i)
y = DirectCast(ipassinfo.GetByIndex(i), user).domestictotal
total = y + total
tb_usertotals.AppendText(x.PadRight(20) & ControlChars.Tab & y.ToString("C") & vbNewLine)
Me.tb_usersmade.Text = i
Next i
Me.Tb_totals.Text = total.ToString("c")
End If
End With
End Sub