A streamreader issue

Max_Payne

New member
Joined
Apr 2, 2004
Messages
3
If you have the following code:

Dim One As New System.IO.StreamReader("file # 1")
Dim Two As New System.IO.StreamReader("file # 2")
Dim Three As New StreamWriter("file # 3")

While One.Read And Two.Read
If Two.Read <> One.Read Then
Three.Write(Two.Read)
End If
End While

One.Close()
Two.Close()

File # 1 has:
1
2
3

File # 2 has:
1
2
3
4
5
6

I want to read from file 1 and file 2. Whenever the reading from file 2 doesnt match the reading from file 1, I want to start saving that reading in file 3. So, at the end, file 3 would have this:
4
5
6

When i run this, the form freezes and file 3 doesnt get updated. Can someone please let me know what i am doing wrong, or maybe have a better suggestion to solving the problem?!

thanks
 
Max_Payne said:
If you have the following code:

Dim One As New System.IO.StreamReader("file # 1")
Dim Two As New System.IO.StreamReader("file # 2")
Dim Three As New StreamWriter("file # 3")

While One.Read And Two.Read
If Two.Read <> One.Read Then
Three.Write(Two.Read)
End If
End While

One.Close()
Two.Close()

File # 1 has:
1
2
3

File # 2 has:
1
2
3
4
5
6

I want to read from file 1 and file 2. Whenever the reading from file 2 doesnt match the reading from file 1, I want to start saving that reading in file 3. So, at the end, file 3 would have this:
4
5
6

When i run this, the form freezes and file 3 doesnt get updated. Can someone please let me know what i am doing wrong, or maybe have a better suggestion to solving the problem?!

thanks
Here is a simple example:
Code:
     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim srf1 As New StreamReader("file1.txt")
        Dim srf2 As New StreamReader("file2.txt")
        Dim srf3 As New StreamWriter("file3.txt")
        Dim strfile1 As New ArrayList
        Dim strfile2 As New ArrayList
        Dim strfile3 As New ArrayList
        Do While srf1.Peek <> -1
            strfile1.Add(srf1.ReadLine)
        Loop
        Do While srf2.Peek <> -1
            strfile2.Add(srf2.ReadLine)
        Loop
        srf1.Close()
        srf2.Close()
        Dim a As Integer
        Dim b As Integer
       
        For a = 0 To strfile1.Count - 1      
            For b = 0 To strfile2.Count - 1
                If strfile1(a) = strfile2(b) Then
                    strfile2.Item(b) = ""                 
                
                End If
            Next

        Next
        Dim x As Integer
        For x = 0 To strfile2.Count - 1
            If strfile2(x) <> "" Then
                srf3.WriteLine(strfile2(x))
            End If
        Next



        srf3.Close()

    End Sub
If your doing a lot of this you might want to put this in a function.
 
Last edited by a moderator:
Back
Top