Procedure Name | Type | Description |
(Declarations) | Declarations | Declarations and private variables for the CCRC16 class. |
InputFileName | Property | Get the name of the input file. |
GetCRCFromFile | Method | Generate a CRC for the file specified in the InputFile property. |
GetCRCFromString | Method | Generate a CRC for a string using the Unicode version of this method. For an ASCII version, see GetCRCFromStringAscii. |
GetCRCFromStringAscii | Method | Generate a CRC for a string using the ASCII version of this method. For the Unicode version, use GetCRCFromString. |
ConstructCRCTable | Private | Fill the CRC table with precalculated values. This is more efficient than calculating CRC's each time they are needed. |
LongToInt | Private | Perform an unsigned conversion from a long value to an integer value. |
ReadFile | Private | Read the specified number of bytes from the file which significantly increases the speed of processing files. The alternative to using a file buffer is reading a byte at a time from the file. |
UpdateCRC16 | Private | Calculate the new CRC based on the current CRC, and the byte value. |
' Example of CCRC16 to calculate the 16-bit CRC of a file or string ' ' To try this example, do the following: ' 1. Create a new user form ' 2. Create a command button named 'cmdTest' ' 3. Paste all the code from this example to the new form's module. ' 4. Run the form ' This example assumes that the sample files are located in the folder named by the following constant. Private Const mcstrSamplePath As String = "C:\TVSBSamp" ' By defining the class WithEvents, you can capture the Progress event to display information to your user. ' To use events, this module must be a class or form/report. If you don't want to capture the Progress event, you can use a regular module. Private WithEvents mclsCRC16 As CCRC16 Private Sub cmdTest_Click() ' Comments: Examples of converting files and strings to a 16-bit Cyclic Redundancy Check (CRC) value; can also be used for Checksum Dim intCRCValue As Integer Dim strString As String ' Initialize Set mclsCRC16 = New CCRC16 ' Example of creating a 16-bit CRC value for a file mclsCRC16.InputFileName = mcstrSamplePath & "\sample.mdb" intCRCValue = mclsCRC16.GetCRCFromFile() MsgBox "File CRC Value:" & intCRCValue ' Example of creating a 16-bit CRC value for a string strString = "One small step for [a] man; one giant leap for mankind" intCRCValue = mclsCRC16.GetCRCFromString(strString) MsgBox "String CRC Value: " & intCRCValue ' Example intCRCValue = mclsCRC16.GetCRCFromStringAscii(strString) MsgBox "Ascii String CRC Value: " & intCRCValue ' Clean up Set mclsCRC16 = Nothing End Sub Private Sub mclsCRC16_Progress(dblPercentage As Double) ' Comments: This procedure captures the Progress Event and reveals the percentage completion for the file that's being compressed ' This example puts the information on the Immediate Window. You could show the information on a form as text or display a graphic. ' Params : dblPercentage Percent of completion between 0 and 1 Debug.Print "Percent done: " & Format$(dblPercentage, "Percent") End Sub
The source code in Total Visual Sourcebook includes modules and classes for Microsoft Access, Visual Basic 6 (VB6), and Visual Basic for Applications (VBA) developers. Easily add this professionally written, tested, and documented royalty-free code into your applications to simplify your application development efforts.
Total Visual SourceBook is written for the needs of a developer using a source code library covering the many challenges you face. Countless developers over the years have told us they learned some or much of their development skills and tricks from our code. You can too!
Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!
"The code is exactly how I would like to write code and the algorithms used are very efficient and well-documented."
Van T. Dinh, Microsoft MVP