Option Strict Compliant

JuggaloBrotha

VB.NET Forum Moderator
Staff member
Joined
Jun 3, 2004
Messages
4,530
Location
Lansing, MI; USA
Programming Experience
10+
What do I change to make this compliant with Option Strict?
VB.NET:
    Private crc32Table() As Integer
    Public Sub New()

        ' This is the official polynomial used by CRC32 in PKZip.
        ' Often the polynomial is shown reversed (04C11DB7).
        Dim dwPolynomial As Integer = &HEDB88320
        Dim i As Integer, j As Integer

        ReDim crc32Table(256)
        Dim dwCrc As Integer

        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 dwPolynomial
                Else
                    dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF
                End If
            Next j
            crc32Table(i) = dwCrc
        Next i
    End Sub

I've attached the entire class as well, it's for getting file's CRC-32 information

The error messages are:
Dissallows convert from Integer to Boolean
If (dwCrc And 1) Then

Dissallows convert from Long to Integer
dwCrc = ((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF

I've never worked with Integers like this before, this is not my original code either
 
Is this the correct fix?
VB.NET:
    Public Sub New()

        ' This is the official polynomial used by CRC32 in PKZip.
        ' Often the polynomial is shown reversed (04C11DB7).
        Dim dwPolynomial As Integer = &HEDB88320
        Dim i As Integer, j As Integer

        ReDim crc32Table(256)
        Dim dwCrc As Integer

        For i = 0 To 255
            dwCrc = i
            For j = 8 To 1 Step -1
                If CBool(dwCrc And 1) = True Then
                    dwCrc = CInt(((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF)
                    dwCrc = dwCrc Xor dwPolynomial
                Else
                    dwCrc = CInt(((dwCrc And &HFFFFFFFE) \ 2&) And &H7FFFFFFF)
                End If
            Next j
            crc32Table(i) = dwCrc
        Next i
    End Sub
 
Back
Top