Question

I'm converting a VB6 program to C#, and I came across the following block of code (b is a byte array from a string, lngLen is a length pointer we're initializing):

If UBound(b) <= 0 Then
    lngLen = UBound(b)
ElseIf UBound(b) >= 2 Then
    If b(UBound(b) - 2) >= 0 And b(UBound(b) - 1) = &HFE And b(UBound(b)) = &HFF Then
        lngLen = UBound(b) - 3
    Else
        lngLen = UBound(b)
    End If
Else
    lngLen = UBound(b)
End If

On line 4 I can tell that it's checking for a BOM in the last two characters of the byte array, but what does the first check for b(UBound(b) - 2) >= 0 do? Isn't it impossible for a byte to be negative?

Was it helpful?

Solution

Yes, it is impossible for a VB6 byte to be negative. The values can only be 0-255 as documented here in the manual.

The check b(UBound(b) - 2) >= 0 will always be True and can be removed from the VB6 code. The check does not need to be migrated to C#.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top