+ Reply to Thread
Results 1 to 12 of 12

Calculate CRC32 checksum :)

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Calculate CRC32 checksum :)

    I want to create a VBA function that can calculate the CRC32 checksum for a file.

    I found this webpage which looks promising: http://www.vbaccelerator.com/home/VB...32/article.asp

    The only catch is that the code provided is VB not VBA. How hard would it be to tweak this code to run in VBA?
    Last edited by mc84excel; 10-14-2013 at 08:43 PM.
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Expert
    Join Date
    02-14-2009
    Location
    .
    MS-Off Ver
    ................
    Posts
    2,840

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :D

    It's a very easy port with minor changes but these are probably in code you will not use.

    Problems:
    Userform (if to be used) needs to be rebuild.
    References to APP object can be replaced with APPLICATION.
    References to PRINTER object and SCREEN object have no direct equivalents in VBA but as they are part of supplementary code can probably be ignored.

    Nothing else noticed on reading* the source, but the core of the calculation should be a simple copy/paste into a class module. There is at least 1 conditional compilation constants (fComponent), this seems to be a flag if the code is part of a system, or a stand alone project. It can be removed or left as is.

    *Note: Code was read, not compiled or tested...

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :D

    Hi cytop.

    I see the userform as unnecessary for my purposes. A simple file picker will do to pick the file and a MsgBox will be sufficient to return the CRC32 result (see attached workbook)

    I'm afraid that I have never learnt classes. :S I have copy/pasted the code into class modules but I get invalid outside procedure messages...
    Attached Files Attached Files

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    Please Login or Register  to view this content.
    Tested on one text file ...
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    Thanks shg +1, this code looks like what I was after.

    Before I mark this as solved however, I am uncertain about the output produced.

    I tried a random file and obtained the CRC32 checksum using your function. It returned a result of 3281A458. I then tested the same file again on an online CRC32 calculator (I googled for one and used this website: http://hash.online-convert.com/crc32-generator) The checksum that this site returned on the uploaded file was 74EF76B6.

    Why the difference?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    The file read probably needs to be changed to a straight binary input. Over to you.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    Ah:

    Please Login or Register  to view this content.

  8. #8
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    I set a reference to Microsoft ActiveX Data Objects 2.0 Library and ended up with a "user defined type" error on the line
    Please Login or Register  to view this content.
    Google provided the solution. You need to use Microsoft ActiveX Data Objects 2.5 Library (or higher version) to prevent this happening.

    I am posting this here in case anyone else runs into this.

  9. #9
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    Brilliant work shg.

    This thread is solved. I am posting my final version of this code below.

    Please Login or Register  to view this content.
    Last edited by mc84excel; 10-14-2013 at 07:47 PM. Reason: solved problem

  10. #10
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum / Convert VB code to VBA code? :)

    This is illogical. I created a dummy test file to compare the CRC32 result against other online calculators. To my surprise, there were a wide variety of results from different systems! How can this be?!


    My test file is attached and the results I received are below:

    D5509719 = Excel function

    3578828569 = Checksum Calculator http://www.checksumcalculator.com/

    D959103E = http://hash.online-convert.com/crc32-generator

    d959103e = online-domain-tools (can't provide URL link - the post crashes whenever I try)

    D5509719 = http://crc32-checksum.waraxe.us/


    UPDATE:

    I realised that there are only two different results in the above, not three. (Checksum Calculator result of 3578828569 = D5509719 in Hex).
    So three different tools are returning D5509719 and two others are returning D959103E
    Attached Files Attached Files
    Last edited by mc84excel; 10-14-2013 at 09:56 PM.

  11. #11
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Calculate CRC32 checksum :)

    To follow/contribute to the next stage of this project, see: http://www.excelforum.com/excel-prog...stage-2-a.html

  12. #12
    Registered User
    Join Date
    06-12-2016
    Location
    Taiwan
    MS-Off Ver
    16.6001.1078
    Posts
    1

    Re: Calculate CRC32 checksum :)

    The CRC32-Mpeg2 seems use different algorithm, the explanation as following:
    http://www.lammertbies.nl/forum/viewtopic.php?t=1398

    And it also calculate by website correcty:
    http://www.sunshine2k.de/coding/java...rc/crc_js.html

    Configuration:
    CRC-32
    CRC32_MPEG2
    Fill Data(00 to FF):
    "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff"

    CRC32_MPEG2 result is "494a116a".

    The algorithm for normal CRC32 as following:
    For I = 0 To 255
    dwCrc = I

    For j = 8 To 1 Step -1
    If (dwCrc And 1) Then
    dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
    dwCrc = dwCrc Xor iPoly
    Else
    dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
    End If
    Next j

    aiCRC(I) = dwCrc
    Next I

    But it seems not suit for CRC32-MPEG2.
    Does someone can help to implement this algorithm? Thanks!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Calculate CCITT 16-bit checksum from string
    By hubertmettwurst in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 11-07-2022, 12:48 AM
  2. [SOLVED] VBA code - Convert one value to another value
    By missy22 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-21-2012, 12:18 PM
  3. how to convert excel split code to word split code
    By gsrikanth in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-02-2012, 07:56 AM
  4. Calculate Checksum
    By Safi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 07-23-2006, 09:40 AM
  5. [SOLVED] Calculate Checksum
    By Safi in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-23-2006, 03:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1