Total Visual SourceBook

Total Visual SourceBook CD and Printed Manual

Microsoft Access/ Office 2016, 2013, 2010, and 2007 Version
is Shipping!

New features in Total Visual SourceBook for Access, Office 2007 and VB6

Supports Access/Office 2016, 2013, 2010 and 2007, and Visual Basic 6.0!

Separate version for Access/Office 2003, 2002, and 2000.

Separate version for:
Access 97/95

View all FMS products for Microsoft AccessAll Our Microsoft Access Products

SourceBook Info:

Why SourceBook?


"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




Microsoft Access, Office/VBA, VB6 Modules royalty-free source code libraryMicrosoft Access Modules royalty-free source code libraryMicrosoft Access VBA and VB6 Module Library Free trial of Total Visual SourceBook for Microsoft Access, Office, VB6 and VBA

Class: CRC16 in Category General VBA/VB6 : Data Integrity from Total Visual SourceBook

Calculate the 16-bit Cyclic Redundancy Check (CRC) of a file or string; can also be used for Checksum in VBA and VB6.

Procedure List

Procedure Name



(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 Code for Using Class: CRC16

' 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

Microsoft Access Module LibraryOverview of Total Visual SourceBook

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.

Additional Resources