ConvertDataTypes.comConvert data types programming in one click !

Convert Byte() to Long in VB

    19086 hits
  • Dim vIn(3) As Byte
  • vIn(0) = &H80
  • vIn(1) = &H0
  • vIn(2) = &H0
  • vIn(3) = &H0
  • Dim vOut As Long
  • For i = 0 To (UBound(vIn) - LBound(vIn))
  • If (i = 0 And ((vIn(0) And &H80) > 0)) Then 'negative value on first byte ?
  • vOut = vOut Or -(CLng(vIn(i)) * (2 ^ (8 * (LenB(vOut) - 1 - i))))
  • Else
  • vOut = vOut Or (CLng(vIn(i)) * (2 ^ (8 * (LenB(vOut) - 1 - i))))
  • End If
  • Next i