Property Get HiByte(ByVal Word As Integer) As Byte
' Devuelve el Byte alto del Word especificado.
'
If Word And &H8000 Then
If Not (Word Or &HFF) = &HFFFFFFFF Then Word = (Word Xor &HFF)
HiByte = &H80 Or ((Word And &H7FFF) \ &HFF)
Else
HiByte = Word \ 256
End If
End Property
Property Get HiWord(Dword As Long) As Integer
' Devuelve el Word alto del DWord especificado.
'
If Dword And &H80000000 Then
HiWord = (Dword / 65535) - 1
Else
HiWord = Dword / 65535
End If
End Property
Property Get LoByte(Word As Integer) As Byte
' Devuelve el Byte bajo del Word especificado.
'
LoByte = (Word And &HFF)
End Property
Property Get LoWord(Dword As Long) As Integer
' Devuelve el Word bajo del DWord especificado.
'
If Dword And &H8000& Then
LoWord = &H8000 Or (Dword And &H7FFF&)
Else
LoWord = Dword And &HFFFF&
End If
End Property
Property Get MakeWord(ByVal bHi As Byte, ByVal bLo As Byte) As Integer
' Crea un Word a partir de sus dos componentes Byte.
'
If bHi And &H80 Then
MakeWord = (((bHi And &H7F) * 255) + bLo) Or &H7FFF
Else
MakeWord = (bHi * 255) + bLo
End If
End Property
Property Get MakeDWord(wHi As Integer, wLo As Integer) As Long
' Crea un DWord a partir de sus dos componentes Word.
'
If wHi And &H8000& Then
MakeDWord = (((wHi And &H8000&) * 65536) Or (wLo And &HFFFF&)) Or &H80000000
Else
MakeDWord = (wHi * &H10000) + wLo
End If
End Property
y la funcion
Function DWordToString(dw As Long) As String
DWordToString = Chr$(LoByte(LoWord(dw))) & _
Chr$(HiByte(LoWord(dw))) & _
Chr$(LoByte(HiWord(dw))) & _
Chr$(HiByte(HiWord(dw)))
End Function
Function StringToDWord(Str As String) As Long
If Len(Str) < 4 Then Str = Str & String$(4 - Len(Str), 0)
StringToDWord = MakeDWord( _
MakeWord( _
Asc(Mid$(Str, 4)), _
Asc(Mid$(Str, 3, 1)) _
), _
MakeWord( _
Asc(Mid$(Str, 2, 1)), _
Asc(Mid$(Str, 1, 1)) _
) _
)
End Function