Applies to  VB5   VB6 

Working with Bytes, Words, and DWords

Extracting Bytes from Words

The LoByte and HiByte functions return the lower (least significant) and upper (most significant) 8 bits of a word (which, like an Integer in Visual Basic, has 16 bits):

For example, LoByte(&H1234) = &H34 and HiByte(&H1234) = &H12.

Combining Bytes into Words

The MakeWord function combines a low byte and a high byte to form a word:

For example, MakeWord(&H34, &H12) = &H1234.

Extracting Words from DWords

The LoWord and HiWord functions return the lower and upper 16 bits of a double word (which, like a Long in Visual Basic, has 32 bits):

For example, LoWord(&H12345678) = &H5678 and HiWord(&H12345678) = &H1234.

LoWord and HiWord both return an Integer. If you'd rather work with Longs, use the LoWordAsLong and HiWordAsLong functions instead:

Combining Words into DWords

The MakeDWord function combines a low word and a high word to form a double word:

(Note that this function is called MAKELONG in the Windows API.)

For example, MakeDWord(&H5678, &H1234) = &H12345678.

See Also

Microsoft Knowledge Base

1