I've been googling this problem for a while and I can't find an answer, I'm writing a program that basically loads an entire text file into a streamreader variable, then reads this variable line by line and parses and writes a line into a new text file. I'm VERY new and my knowledge is mostly self-taught, but I can't seem to get out of this one. It works for smaller files, but it appears to reach a limit in characters at some point because in a file of 900 lines, it stops writing about halfway through 800 and there are no errors, the program actually completes and the message box pops up.
I appreciate that there are probably better ways to do this, I'd like to learn how, but this is all I know so far. There are a few things with this code I already know I should fix, such as creating the new text file name, it's messy, I just don't know how. Hopefully someone can help point me in the right direction.
I appreciate that there are probably better ways to do this, I'd like to learn how, but this is all I know so far. There are a few things with this code I already know I should fix, such as creating the new text file name, it's messy, I just don't know how. Hopefully someone can help point me in the right direction.
VB.NET:
Private Sub btnProcess_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnProcess.Click
Dim IndexValues As String()
Dim TextPath As String = txtFilePath.Text.ToString
Dim TextFile As StreamReader
Dim FinalFile As StreamWriter
Dim GarbagePath As String()
Dim i As Integer
Dim ID As Integer = 1
If File.Exists(TextPath) Then
TextFile = File.OpenText(TextPath)
End If
FinalFile = File.CreateText(TextPath & ".csv")
FinalFile.WriteLine("ID,Company Number,File Cabinet,Invoice Number,Supplier Code,Filename")
Do Until TextFile.Peek() = -1
IndexValues = TextFile.ReadLine().Split(",")
GarbagePath = IndexValues(IndexValues.GetUpperBound(0)).Split("\")
For i = 0 To IndexValues.GetUpperBound(0)
IndexValues(i) = Replace(IndexValues(i), Chr(34), "")
GarbagePath(GarbagePath.GetUpperBound(0)) = Replace(GarbagePath(GarbagePath.GetUpperBound(0)), _
Chr(34), "")
Next
FinalFile.WriteLine(ID & "," & IndexValues(3) & "," & IndexValues(5) & "," & IndexValues(7) & "," & IndexValues(9) _
& "," & GarbagePath(GarbagePath.GetUpperBound(0)))
ID += 1
Erase IndexValues
Loop
MessageBox.Show("Invoices Complete!")
End Sub
Last edited by a moderator: