hi guys,
I'm trying to form 4 byte values into a long value (i.e. (hex values) bytes FC 24 23 67 becomes long value FC242367) and i keep getting overflow errors which i believe are due to sign extension problems.
Here is a bit of demo code i have been using to form XX000000 (where XX is the byte value)
----
Dim MyByte As Byte
Dim MyLong As Long
MyByte = CByte("&H7F"
' Give byte value of '7F'
MyLong = MyByte * CLng(&H1000000) ' Want MyByte to be MS byte in long
MsgBox Hex(MyLong) ' Gives output of '7F000000'
MyByte = CByte("&H80"
' Now give byte value of '80'
MyLong = MyByte * CLng(&H1000000) ' Want MyByte to be MS byte in long - get overflow here
MsgBox Hex(MyLong)
----
I have actually solved the problem by converting the byte into a string and concatanating the 6 trailing 0's on but i'm sure there must be a better way.
Any ideas?
Dave
I'm trying to form 4 byte values into a long value (i.e. (hex values) bytes FC 24 23 67 becomes long value FC242367) and i keep getting overflow errors which i believe are due to sign extension problems.
Here is a bit of demo code i have been using to form XX000000 (where XX is the byte value)
----
Dim MyByte As Byte
Dim MyLong As Long
MyByte = CByte("&H7F"
MyLong = MyByte * CLng(&H1000000) ' Want MyByte to be MS byte in long
MsgBox Hex(MyLong) ' Gives output of '7F000000'
MyByte = CByte("&H80"
MyLong = MyByte * CLng(&H1000000) ' Want MyByte to be MS byte in long - get overflow here
MsgBox Hex(MyLong)
----
I have actually solved the problem by converting the byte into a string and concatanating the 6 trailing 0's on but i'm sure there must be a better way.
Any ideas?
Dave