Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim m(5), x(5) As Byte
        For i As Integer = 0 To 4
            m(i) = i
        Next
        x(2) = -m(4)'Here it shows error
        MsgBox(x(2))



The line at x(2) = -m(4) shows an Error. :-O
Is there any method to convert a byte value to it's -ve equivalent and store it in another byte variable????
Posted

You can't.
Byte is an UNSIGNED data type (MSDN on Byte[^])
Since it has no sign, it cannot be negative!

In future, post the error message as well - it helps us to work out what you are having difficulties with.
 
Share this answer
 
You can cast it to an int or a short, then flip the sign - but you'd need to change your design a little to accommodate for non-byte storage.
 
Share this answer
 
Thanks Everyone I have casted it to short and it works great

:cool::cool::cool::cool::cool:
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900