Hi
I have code that steps through and reads text files from a list box (listbox2), modifies the text, adds the text to a second list box (listbox1) and writes the modified text from the listbox1 to a new text file. I am trying to add a progress bar code to display the progress of each text file modified and written.
I have been playing with the code but the progress bar either shows no progress or shows progress after all the code has completed.
Here is my code:
Any help would be appreciated
I have code that steps through and reads text files from a list box (listbox2), modifies the text, adds the text to a second list box (listbox1) and writes the modified text from the listbox1 to a new text file. I am trying to add a progress bar code to display the progress of each text file modified and written.
I have been playing with the code but the progress bar either shows no progress or shows progress after all the code has completed.
Here is my code:
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim i As Integer
For i = 0 To ListBox2.Items.Count - 1
ListBox1.Items.Clear()
Dim myfile = ListBox2.Items(i)
Dim mystream As New IO.FileStream(myfile, IO.FileMode.Open, IO.FileAccess.Read) ' Create a new file stream to hold the contents of the file
Dim sr As New IO.StreamReader(mystream) ' Use SR to read our new stream
Dim buffer As String = Nothing ' Used as a temporary holder
Do While sr.EndOfStream = False ' Do the loop until we have reached the end of the file
buffer = sr.ReadLine ' Throw the line into buffer
If buffer <> Nothing And buffer.StartsWith("#") Then ' If buffer is not a blank line or does not start with @
ListBox1.Items.Add(buffer + " " + (Regex.Match(buffer, "(\w+)").Groups(1).ToString()))
Else
ListBox1.Items.Add(buffer)
End If
Loop
sr.Close() ' Close the stream reader.
mystream.Close() ' Close the stream.
Dim i1 As Integer
Dim s As String
If ListBox1.Items.Count > 0 Then
Dim file As New System.IO.StreamWriter(ListBox2.Items.Item(i).ToString + "_MarkedUp.txt", True, System.Text.Encoding.UTF8)
For i1 = 0 To ListBox1.Items.Count - 1
s = ListBox1.Items.Item(i1)
file.WriteLine(s)
Next i1
file.Close()
End If
Next
End Sub