Search code examples
vb.netbasic

(in Visual Basic) Is it possible to "loop" or "rotate" through a byte, without using an( if-then-tree) or (and &HFF)?


What I mean is: If a byte has value of 255, and I add 1. It becomes 0 again. Or if I subtract 1 from a zero value it becomes 255. I have a lot of code, that treats bytes like this, and I'd rather not sift through all them lines to find occurrences of such rotations

Well, nothing ventured and all that...

Cheers Jhonny

Edit: Just a dumb example:

Sub Tester()
        Dim Arr(255) As Byte
        Dim BytePointer As Byte = 200
        Dim value As Byte
        Arr(50) = 1
        For i = 0 To 5000
            BytePointer = BytePointer + 1
            value = Arr(BytePointer)
            If value = 1 Then MessageBox.Show("Found 1")
        Next
end sub

As such it results in an overflow exception.

Can this work without doing:

BytePointer = (BytePointer + 1) and &FF

Solution

  • OK....

    By "Removing integer overflow checks in the Advanced Compiler Options dialog", you can wrap-around bytes and integers, without overflow-errors.

    But it does so for the whole project.

    I can work with this...

    It's a shame though, that VB does not offer variables (let's call them winteger or wbyte) that do this by default. (just my 2 cents...)