0

I am quite new to VB.NET and I am trying to implement something in Visual Studio 2013 to calculate the CRC-32 bytes of an array of bytes. I have come across a variety of examples, some in VB.NET and some in C#. Nonetheless, I have not been successful in getting them to work or even test them.

For example consider this particular code from "Mangus" which I found on this website. I copied and pasteed it into a windows form template and I get this error:

error BC30456: 'Dump' is not a member of 'UInteger'.

I apologize as I might be doing something really silly, but I appreciate any help or hints.

Private Sub Main()
   Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")).Dump()
End Sub

Public Class Crc32
   Shared table As UInteger()

   Shared Sub New()
      Dim poly As UInteger = &Hedb88320UI
      table = New UInteger(255) {}
      Dim temp As UInteger = 0
      For i As UInteger = 0 To table.Length - 1
         temp = i
         For j As Integer = 8 To 1 Step -1
            If (temp And 1) = 1 Then
               temp = CUInt((temp >> 1) Xor poly)
            Else
               temp >>= 1
            End If
         Next
         table(i) = temp
      Next
   End Sub

   Public Shared Function ComputeChecksum(bytes As Byte()) As UInteger
      Dim crc As UInteger = &HffffffffUI
      For i As Integer = 0 To bytes.Length - 1
         Dim index As Byte = CByte(((crc) And &Hff) Xor bytes(i))
         crc = CUInt((crc >> 8) Xor table(index))
      Next
      Return Not crc
   End Function
End Class
Dave Cousineau
  • 12,154
  • 8
  • 64
  • 80
Jamy codes
  • 101
  • 2
  • 8
  • Dump() seems to be there only to output the result (for testing?). Does the rest of the code compile? – Joachim Isaksson Jul 23 '14 at 05:39
  • This code will not compile because "Dump" is not a function that belongs to UInteger. Can you provide a link to the original code? It's possible you copied something incorrectly or incompletely. (Or the author just intended for this to be pseudocode) – Alex Jul 23 '14 at 05:40
  • If you do not understand the code enough to rewrite the line in Main so it does not need the Dump method, you should probably not use it. – nvoigt Jul 23 '14 at 05:41
  • 1
    Could you add the link to the website from which you got the code please? I assume there was supposed to be a link since you said "this website"? – yu_ominae Jul 23 '14 at 06:02
  • This is the website at the bottom of the page you will find the code by "Magnus": http://stackoverflow.com/questions/15553697/calculate-crc32-of-an-string-or-byte-array – Jamy codes Jul 23 '14 at 07:42

1 Answers1

0

If you copied this from somewhere else then I am guessing that Dump is an extension method to do something like Debug.Print

Try replacing this:

Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")).Dump()

With this:

Debug.Print(Crc32.ComputeChecksum(Encoding.UTF8.GetBytes("Some string")))
Matt Wilko
  • 26,994
  • 10
  • 93
  • 143
  • Thanks Matt. Your modification got rid of the error message, but I can not see the result that the code is producing. Could I see the CRC value that is being returned? – Jamy codes Jul 23 '14 at 07:57
  • It should print into the output (or possibly immediate) window (if you are running a debug build) – Matt Wilko Jul 23 '14 at 07:59
  • I was expecting to see CRC bytes in the immediate or output window, but apparently there is nothing. – Jamy codes Jul 23 '14 at 08:21
  • That is another question (that I'm sure has been asked before so just google it), to see your checksum just show it in a `MsgBox` – Matt Wilko Jul 23 '14 at 08:31