Applies to VB4+ |
The UIntToLong function treats an Integer as if it were unsigned and converts it to a Long, resulting in a number between 0 and 65535 (&HFFFF&
):
UIntToLong preserves the bits of the integer that's passed to it. For example, UIntToLong(&H1234) = &H1234&
and UIntToLong(&HFEDC) = &HFEDC&
. (Note that &HFEDC
equals -292 while &HFEDC&
equals 65244.)
The LongToUInt function does the opposite, converting a Long between 0 and 65535 to an Integer with the same bits:
For example, LongToUInt(&H1234&) = &H1234
and LongToUInt(&HFEDC&) = &HFEDC
.
The GIF file format uses two unsigned integer fields to store the width and height of an image. The following procedure reads a GIF file and displays the size of the image:
' Outputs the size of a GIF image to the Immediate window. Public Sub DisplayGIFImageSize(FileName As String) Dim FileNum As Integer, Width As Integer, Height As Integer FileNum = FreeFile Open FileName For Binary Access Read Lock Write As FileNum Get #FileNum, 7, Width Get #FileNum, 9, Height Close FileNum Debug.Print "Width = " & UIntToLong(Width) Debug.Print "Height = " & UIntToLong(Height) End Sub
Copyright © 2001 Rising Productions.