Next Generation Emulation banner

1 - 12 of 12 Posts

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #1
Hey guys, currently this code checks for differences between 2 text files. One of these files is bigger then the other. Problem is that this code only checks until the end of one of the files. Also, if any lines were deleted from the 2nd file, the whole code logic would go haywire.
Can anyone guide me as to how to modify the code so that it'll be able to check until the end of both files, which lines are missing from file 1 and file 2.
Like lets say file 1 has test=test but file 2 doesnt have it.
It'll show like file 2 doesnt have test = test
If file 2 has t = t but file 1 doesnt.
It'll show like file 1 doesnt have t = t
This is the code. Really hope someone can help

Regards

Dim fsRegPre As New FileStream("snapRegPre.tmp", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim fsRegNew As New FileStream("snapRegNew.tmp", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)

'declaring a FileStream to open the file named file.doc with access mode of reading
Dim srRegPre As New StreamReader(fsRegPre)
Dim srRegNew As New StreamReader(fsRegNew)
'creating a new StreamReader and passing the filestream object fs as argument
srRegPre.BaseStream.Seek(0, SeekOrigin.Begin)
srRegNew.BaseStream.Seek(0, SeekOrigin.Begin)
'Seek method is used to move the cursor to different positions in a file, in this code, to the beginning
'peek method of StreamReader object tells how much more data is left in the file
Dim regTempNew As String = srRegNew.ReadLine
Dim regTempPre As String = srRegPre.ReadLine
Dim x As ListViewItem
While srRegNew.Peek > -1 Or srRegPre.Peek > -1
If Not regTempNew Is Nothing Then
If regTempNew.ToLower.StartsWith("[hkey") Then
Label1.Text = regTempNew
End If
If regTempNew.CompareTo(regTempPre) = 0 Then
regTempPre = srRegPre.ReadLine()
Else
If Not regTempNew.ToLower.StartsWith("[hkey") Then
x = frmC.ListView2.Items.Add("")
x.SubItems.AddRange(New String() {Label1.Text & "\\" & regTempNew})
'ListBox1.Items.Add(Label1.Text & "\\" & regTempNew)
Else
x = frmC.ListView2.Items.Add("")
x.SubItems.AddRange(New String() {regTempNew})
'ListBox1.Items.Add(regTempNew)
End If
End If
regTempNew = srRegNew.ReadLine()
End If
End While
 

·
OUYA Angel Backer
Joined
·
197 Posts
I hate VB and all things Microsoft and I haven't coded VB in literally years, but I might be able to help you. I only quickly read the code over, but...

Janus said:
While srRegNew.Peek > -1 Or srRegPre.Peek > -1
Try changing the Or to an And. That should solve your problem with the code stopping when one file is done but not the other.
 

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #3
I have thought of that. but if one reaches the end of file before the other and i continue looping, wouldnt that give me a EOF exception?
Yeah..i agree. VB is...doh. java is so much better..but not much choice this time since some of the methods that i need are already coded in vb.net
 

·
Emulation to the max!
Joined
·
2,560 Posts
You should really have two spearte loops, one for each file. Try making a sperate method that does the checking and has a file as the parameter passed in, then call the method twice with each file seperatly. That should fix your problem and make nicer looking code. BTW havent programmed in vb.net in aggggggges.
 

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #5
hm..2 seperate loops...meaning i just switch the file 1 and file 2 around in the next loop. That might be feasilbe, but still there's the problem of like..lets say File 1 has a line that file 2 doesnt have. Then the whole logic will go mad and start printing out every line starting from where this started. thats the main problem right now for me
 

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #7
well, i would do the 2 loops way. problem is filtering out which are the actual missing entries and which are not, since once there is a missing line the whole logic will go haywire. I have thought of goin through the each file line by line checking against the other file. But that will take..ages? right?
 

·
OUYA Angel Backer
Joined
·
197 Posts
Maybe. VB isn't exactly a fast language. But I think you're underestimating the power of a modern processor a bit too. It also depends on how large these files are.
 

·
Registered
Joined
·
2,583 Posts
Kethinov said:
Maybe. VB isn't exactly a fast language. But I think you're underestimating the power of a modern processor a bit too. It also depends on how large these files are.
This is VB.NET he's talking about. It's been completely redesigned since VB6 and boasts significant speed gains. It's basically on par with all the other .NET languages and C/C++ in most cases.
 

·
Memories are all I have..
Joined
·
423 Posts
Discussion Starter #10
underestimating? either that or my algo is kinda screwed up since im comparing line by line. Even with this code it doesnt finish comparing the 2 files..it kinda like hangs there after awhile. think i over exceeded the limit or something..unless someone can point me to a better data stuctured algo?
 

·
Registered
Joined
·
1,577 Posts
By the way, there is a CODE bbcode tag. Also, you should try intenting your code as it would improve code readability 10-fold.

Code:
'declaring a FileStream to open the file named file.doc with access mode of reading
Dim fsRegPre As New FileStream("snapRegPre.tmp", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim fsRegNew As New FileStream("snapRegNew.tmp", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)

'creating a new StreamReader and passing the filestream object fs as argument
Dim srRegPre As New StreamReader(fsRegPre)
Dim srRegNew As New StreamReader(fsRegNew)

'Seek method is used to move the cursor to different positions in a file, in this code, to the beginning
'peek method of StreamReader object tells how much more data is left in the file
srRegPre.BaseStream.Seek(0, SeekOrigin.Begin)
srRegNew.BaseStream.Seek(0, SeekOrigin.Begin)

Dim regTempNew As String = srRegNew.ReadLine
Dim regTempPre As String = srRegPre.ReadLine
Dim x As ListViewItem

While srRegNew.Peek > -1 Or srRegPre.Peek > -1
    If Not regTempNew Is Nothing Then
        If regTempNew.ToLower.StartsWith("[hkey") Then
            Label1.Text = regTempNew
        End If

        If regTempNew.CompareTo(regTempPre) = 0 Then
            regTempPre = srRegPre.ReadLine()
        Else
            If Not regTempNew.ToLower.StartsWith("[hkey") Then
                x = frmC.ListView2.Items.Add("")
                x.SubItems.AddRange(New String() {Label1.Text & "\\" & regTempNew})
                'ListBox1.Items.Add(Label1.Text & "\\" & regTempNew)
            Else
                x = frmC.ListView2.Items.Add("")
                x.SubItems.AddRange(New String() {regTempNew})
                'ListBox1.Items.Add(regTempNew)
            End If
        End If

        regTempNew = srRegNew.ReadLine()
    End If
End While
 

·
OUYA Angel Backer
Joined
·
197 Posts
FLaRe85 said:
This is VB.NET he's talking about. It's been completely redesigned since VB6 and boasts significant speed gains. It's basically on par with all the other .NET languages and C/C++ in most cases.
I stopped coding VB when VB6 was a new thing, before .NET was around. I'll have to largely take your word on this, but AFAIK .NET languages (such as C#) are definitely not up to par with C/C++ in speed. Though they are faster than the VB I remember.
 
1 - 12 of 12 Posts
Top