Resumen Numeros con signo

Sacado del web de Microsoft :

En VB los enteros van de -32768 a +32767 y los long de -2147483648 a
2147483647. A veces necesitamos pasar al funciones del API o a Dll's
escritas en c números sin signo de 0 a 65535 o de 0 a 4294967296.

UnsignedToLong
Esta función coge un Double con valor apto para un unsigned Long y devuelve
un Long que se puede pasar a una dll que necesite long sin signo.


LongToUnsigned
Esta función coge un long sin signo que devuelva una dll y devuelve un Double.


UnsignedToInteger
Esta función coge un Long con valor apto para un entero sin signo y
devuelve un Integer que se puede pasar a una dll que necesite Integer sin
signo.


IntegerToUnsigned
Esta función coge un Integer sin signo que devuelva una dll y devuelve un
Long.

Private Const OFFSET_4 = 4294967296#
Private Const MAXINT_4 = 2147483647
Private Const OFFSET_2 = 65536
Private Const MAXINT_2 = 32767


Function UnsignedToLong(Value As Double) As Long
  If Value < 0 Or Value >= OFFSET_4 Then Error 6 ' Overflow
  If Value <= MAXINT_4 Then
     UnsignedToLong = Value
  Else
     UnsignedToLong = Value - OFFSET_4
  End If
End Function

Function LongToUnsigned(Value As Long) As Double
  If Value < 0 Then
     LongToUnsigned = Value + OFFSET_4
  Else
     LongToUnsigned = Value
  End If
End Function

Function UnsignedToInteger(Value As Long) As Integer
  If Value < 0 Or Value >= OFFSET_2 Then Error 6 ' Overflow
  If Value <= MAXINT_2 Then
     UnsignedToInteger = Value
  Else
     UnsignedToInteger = Value - OFFSET_2
  End If
End Function

Function IntegerToUnsigned(Value As Integer) As Long
  If Value < 0 Then
     IntegerToUnsigned = Value + OFFSET_2
  Else
      IntegerToUnsigned = Value
  End If
End Function



Un saludo.

_________________________________________________
José Rubí de la Vega
E-mail : jrubi@arrakis.es
WWW : http://www.arrakis.es/~jrubi
Podrás encontrar información sobre VB, la lista
VB-ESP y un resumen de los mensajes de la misma



Resumen Resumen

Visual Basic Página de Visual Basic

Página principal Página principal

www.jrubi.com