Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
CRC32 and object reference not set
Message
From
09/10/2006 00:07:08
 
 
To
All
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Title:
CRC32 and object reference not set
Environment versions
Environment:
VB 8.0
OS:
Windows XP SP2
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01160445
Message ID:
01160445
Views:
45
I have a CRC32 method which is like this:
        Public cFileName As String = ""
        Public nCRC32 As Integer = 0
        Private nBufferSize As Integer = 1024
        Private nCRC32Table() As Integer

        ' This is the official polynomial used by CRC32 in PKZip.
        ' Often the polynomial is shown reversed (04C11DB7).
        Private Sub Init()
            Dim lnDWPolynomial As Integer = &HEDB88320
            Dim lnCounter As Integer = 0
            Dim lnCounter2 As Integer = 0
            ReDim nCRC32Table(256)
            Dim lnDWCRC As Integer

            For lnCounter = 0 To 255
                lnDWCRC = lnCounter
                For lnCounter2 = 8 To 1 Step -1
                    If (lnDWCRC And 1) Then
                        lnDWCRC = ((lnDWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
                        lnDWCRC = lnDWCRC Xor lnDWPolynomial
                    Else
                        lnDWCRC = ((lnDWCRC And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
                    End If
                Next
                nCRC32Table(lnCounter) = lnDWCRC
            Next

        End Sub

        ' This is the main method to call
        Public Function GetCRC() As Boolean
            Dim loStream As Stream
            loStream = New FileStream(cFileName, FileMode.Open, FileAccess.Read, FileShare.Read, 8192)
            nCRC32 = GetCrc32(loStream)
            loStream.Close()
            Return True
        End Function

        Private Function GetCrc32(ByRef toStream As System.IO.Stream) As Integer
            Dim lnCRC32Result As Integer = &HFFFFFFFF
            Dim loBuffer(nBufferSize) As Byte
            Dim lnReadSize As Integer = nBufferSize
            Dim lnCount As Integer = 0
            Dim lnCounter As Integer = 0
            Dim lnLookup As Integer = 0

            lnCount = toStream.Read(loBuffer, 0, lnReadSize)
            Do While lnCount > 0
                For lnCounter = 0 To lnCount - 1
                    lnLookup = (lnCRC32Result And &HFF) Xor loBuffer(lnCounter)

                    ' Nasty shr 8 with vb :/
                    lnCRC32Result = ((lnCRC32Result And &HFFFFFF00) \ &H100) And 16777215

                    lnCRC32Result = lnCRC32Result Xor nCRC32Table(lnLookup)
                Next
                lnCount = toStream.Read(loBuffer, 0, lnReadSize)
            Loop
            Return Not lnCRC32Result
        End Function
This method has always worked well. However, tonight, on a specific JPG, it returns:

"Object reference not set to an instance of an object."

This is in regards to the line:
                    lnCRC32Result = lnCRC32Result Xor nCRC32Table(lnLookup)
I really don't understand how this line could return an object reference not set. Anyone would have any idea and also about what is causing this?
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform