Try:
Debug Hex(a & $FF)
I haven't tested it but I'm pretty sure I know what the problem is as I keep forgetting that bytes are signed in PB.
So instead of being ranged from 0 - 255 (unsigned byte), they range from -127 to 127.
Yes the problem is the unsigned bytes. I think PB should do variable bounds checking with debugger. At least at compile time. And I would like unsigned bytes.
a.b=255
Debug Hex(Val(StrU(a,#Byte))) ;print the unsigned value
Debug Hex(Val(Str(a))) ;print the signed value
Debug Hex(a) ;print the signed value
Debug Hex(255)