VB6 - Signed/Unsigned Integer Conversions [Archive] - ForumsHQ

Post Reply
syntax53
Posts: 0
Joined: Wed Apr 03, 2002 6:00 am

VB6 - Signed/Unsigned Integer Conversions [Archive] - ForumsHQ

Post by syntax53 »

Constants



Global Const LongOffset = 4294967296#

Global Const MaxLong = 2147483647

Global Const IntOffset = 65536

Global Const MaxInt = 32767



Unsigned Long to Signed Long



Public Function ULong2SLong(ByVal value As Variant) As Long

On Error GoTo error:

If value >= LongOffset Then value = LongOffset - 1

If value MaxLong Then value = MaxLong

If value = IntOffset Then value = IntOffset - 1

If value MaxInt Then value = MaxInt

If value < 0 Then

SInt2UInt = value + IntOffset

Else

SInt2UInt = value

End If

Exit Function

error:

HandleError

End Function



Error Handler



Public Sub HandleError()



MsgBox Err.Source & vbCrLf & "Error " & Err.Number & ": " & Err.Description, vbExclamation



Err.Clear

End Sub
Post Reply

Return to “Programming, web design & Graphics”