VB and VBA Users Source Code: Determining the check sum of a file
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Determining the check sum of a file
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Sunday, June 25, 2000
Hits:
707
Category:
Files/Directories/IO
Article:
Check sums are a useful way of determining if a file has been altered. The routine below calculates a file check sum as a long integer. 'Purpose : Returns a file checksum 'Inputs : sFile The path and file name of the file to calculate the check sum on 'Outputs : Returns -1 on error else returns the file check sum. 'Author : Andrew Baker 'Date : 06/07/2002 'Notes : 'Example : 'Revisions : Public Function FileChecksum(ByVal sFile As String) As Long Dim hwdFile As Long Dim lSum As Long Dim byChar As Byte Dim sLine As String Dim lChar As Long On Error GoTo ErrFailed hwdFile = FreeFile Open sFile For Input As hwdFile lSum = 0 sChecksum = "" Do Until EOF(hwdFile) Line Input #hwdFile, sLine For lChar = 1 To Len(sLine) lSum = lSum + Asc(Mid$(sLine, lChar, 1)) Next Loop FileChecksum = lSum Close hwdFile Exit Function ErrFailed: Close hwdFile FileChecksum = -1 Debug.Print Err.Description Debug.Assert False End Function Sub Test() Debug.Print FileChecksum("c:\setup.exe") End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder