04-18-2011, 01:34 PM
My Turn!!?!?!
I didn't get around to error handling and checking if the files in the textbox were valid files. But I will implement that later. Also when I have time I'm going to try this out in C# as well.
Looks I'm the lone wolf when it comes to the way we did this project! My code is pretty simple though. Looks like everyone did it the hard way!
Everybody's seemed to get their programs to work. Another challenge bites the dust.
@Infinity
What are you using this for? Im thinking you forgot to take it out?
I don't see why not!
Where are the comment's yo?!?
Here's mine: (Click to View)
Screenshot:
Click here to download the exe
Click here to download a demo project
Source (Commented):
Click here to download the exe
Click here to download a demo project
Source (Commented):
Code:
Imports System.Security.Cryptography
Imports System.IO
Public Class Form1
Private Sub btnCheck_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCheck.Click
'Create a new MD5 class
Dim hash As MD5 = MD5.Create()
'Compute the Hash of both files
Dim File1 As Byte() = hash.ComputeHash(My.Computer.FileSystem.ReadAllBytes(txtFile1.Text))
Dim File2 As Byte() = hash.ComputeHash(My.Computer.FileSystem.ReadAllBytes(txtFile2.Text))
'Convert the bytes to a readable string and take out the hyphens
Dim strFile1 As String = BitConverter.ToString(File1).Replace("-", "")
Dim strFile2 As String = BitConverter.ToString(File2).Replace("-", "")
'sets the lables to the string version of the MD5 Hash
lblFile1MD5.Text = strFile1
lblFile2MD5.Text = strFile2
'This is just one way to check, but it compares the string
'representation of the computed hash to check if it's the same
If strFile1 = strFile2 Then
lblResult.ForeColor = Color.LimeGreen
lblResult.Text = "The file has not been modified."
Else
lblResult.ForeColor = Color.Red
lblResult.Text = "The file has been modified."
End If
lblLast.Text = Path.GetFileName(txtFile2.Text)
End Sub
Private Sub btnFile1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile1.Click
'new instance of an OpenFileDialog
Dim oFile As OpenFileDialog = New OpenFileDialog
'if they hit anything but OK do nothing
If Not oFile.ShowDialog() = DialogResult.OK Then Exit Sub
txtFile1.Text = oFile.FileName
End Sub
Private Sub btnFile2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFile2.Click
Dim oFile As OpenFileDialog = New OpenFileDialog
If Not oFile.ShowDialog() = DialogResult.OK Then Exit Sub
txtFile2.Text = oFile.FileName
End Sub
End Class
I didn't get around to error handling and checking if the files in the textbox were valid files. But I will implement that later. Also when I have time I'm going to try this out in C# as well.
Looks I'm the lone wolf when it comes to the way we did this project! My code is pretty simple though. Looks like everyone did it the hard way!
Everybody's seemed to get their programs to work. Another challenge bites the dust.
@Infinity
What are you using this for? Im thinking you forgot to take it out?
Code:
Dim ObjFSO As Object = CreateObject("Scripting.FileSystemObject")
Dim objFile = ObjFSO.GetFile(TextBox1.Text)
(04-18-2011, 12:54 PM)Fragma Wrote: [ -> ]By the way guys.. Can I host the next challenge?
I don't see why not!
(04-18-2011, 10:21 AM)The High Roller Wrote: [ -> ]My Submission:
Spoiler (Click to View)Screenshot:
Download Link:
Source Code:Code:http://www.mediafire.com/?cp96hb8n4wx4uhn
Code:Public Class Form1
Public Function VerifyMD5HashCode(ByVal filepath As String) As String
Using verifythefile As New System.IO.FileStream(filepath, IO.FileMode.Open, IO.FileAccess.Read)
Using themd5code As New System.Security.Cryptography.MD5CryptoServiceProvider
Dim thahash() As Byte = themd5code.ComputeHash(verifythefile)
Return ByteArrayToString(thahash)
End Using
End Using
End Function
Private Function ByteArrayToString(ByVal arrInput() As Byte) As String
Dim StringBuilder As New System.Text.StringBuilder(arrInput.Length * 2)
For i As Integer = 0 To arrInput.Length - 1
StringBuilder.Append(arrInput(i).ToString("X2"))
Next
Return StringBuilder.ToString().ToLower
End Function
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
MD5Hash1.Text = VerifyMD5HashCode(filepath1.Text)
MD5Hash2.Text = VerifyMD5HashCode(filepath2.Text)
If filepath1.Text = filepath2.Text Then
MsgBox("The selected files are the same.", 64, "File Comparison Result")
TrueResults.Text = "Both Files Are Identical"
TrueResults.ForeColor = Color.LimeGreen
Else
MsgBox("The selected files are different.", 48, "File Comparison Result")
TrueResults.Text = "Both Files Are Unidentical"
TrueResults.ForeColor = Color.Red
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SelectFiles.ShowDialog()
SelectFiles.Title = "Select File #1..."
End Sub
Private Sub SelectFiles_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SelectFiles.FileOk
Dim file1 As String = SelectFiles.FileName
filepath1.Text = file1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SelectFiles2.ShowDialog()
SelectFiles2.Title = "Select File #2..."
End Sub
Private Sub SelectFiles2_FileOk(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles SelectFiles2.FileOk
Dim file2 As String = SelectFiles2.FileName
filepath2.Text = file2
End Sub
Private Sub filepath2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles filepath2.TextChanged
Button3.Enabled = True
End Sub
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
Process.Start("http://www.supportforums.net/member.php?action=profile&uid=4502")
End Sub
End Class
Now this is what I call useful for something in the future. Great idea Infinity.
Where are the comment's yo?!?