Good day,
I am having an issue importing text data into an array. The text data is in the following tab-delimited format (cost type accountcode):
0.60 Duplicating 2780100
0.20 Duplicating 2975650
0.20 Duplicating 3190200
1.20 Duplicating 3370850
My goal is to import the data into an array, run through the data, totaling up any costs where the account code, for example "2780100" matches, and then export the data back to a text file with only one instance of each account code with the total cost associated with that account.
This is a work in progress. Right now I am just trying to import the data, and then export it to check on my parsing. The code does not show any errors, but when I run it, I get a first chance exception error, and nothing is imported or exported.
Can anyone help me to see the errors of my ways?
CODE
Option Explicit On
Option Strict On
Public Class MainForm
Public filecontents As String
Private Sub MainForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
' load from the text file the product item numbers nad prices
' declare the variables used
Dim inputfile As String = "C:\Visual Studio 2005\Projects\SummarizeExports\SummarizeExports\bin\Debug\Exports.txt"
' check to make sure the file exists, and if yes then
' get the contents of the file. If not, display message.
If My.Computer.FileSystem.FileExists(inputfile) Then
filecontents = My.Computer.FileSystem.ReadAllText(inputfile)
Call Process_Export_File()
Else
MessageBox.Show("File does not exist", "Exports.txt", _
MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
' close the application
Me.Close()
End Sub
Private Sub Process_Export_File()
' dimension array to store each line in the Exports.txt file
Dim counter As Integer = 0
Dim lineindex As Integer
Dim transaction() As String = Split(filecontents, vbCrLf)
Dim cost(lineindex) As String
Dim client(lineindex) As String
Dim duplicating As String = "Duplicating"
Dim position As Integer = 1
Dim newposition As Integer
' find first newline in string
lineindex = filecontents.IndexOf(ControlChars.NewLine)
' run through data to store each transaction in the transaction array
Do Until lineindex - counter <= 0
position = transaction(counter).IndexOf("Duplicating", 0)
newposition = position + 11
' get the cost value of the transaction
cost(counter) = transaction(counter).Substring(1, position)
cost(counter) = cost(counter).Trim
' get the client number for the transaction
client(counter) = transaction(counter).Substring(newposition, 6)
client(counter) = client(counter).Trim
Const File As String = "TestExport.txt"
My.Computer.FileSystem.WriteAllText(File, _
cost(counter) & _
" " & duplicating & _
" " & client(counter) & _
ControlChars.NewLine, True)
' update the counter and loop
counter = counter + 1
Loop
End Sub
End Class