Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

How To Use an Ampersand (&) to Suppress Sign Extension


Summary

Adding an ampersand (&) character to the end of a Hexadecimal number will ensure that it is not sign extended. This can be useful when an unsigned constant must be passed to a routine and the magnitude of the constant is greater than or equal to 32,768 (&H8000 in Hexadecimal). If the ampersand is not placed on the end of the constants, Visual Basic assumes that the numbers are sign extended.

↑ Back to the top


More Information

The following example illustrates the effect of an ampersand on a Hexadecimal constant:


  1. Start a new project in Visual Basic. In the default form (Form1), place the following code in the Click event for the form:

          Private Sub Form_Click()
    Dim j As Long
    j = &H8000
    Debug.Print j
    j = &H8000&
    Debug.Print j
    End Sub
  2. Run the code by pressing the F5 key. The Debug window shows the output as -32,768 followed by 32,768 indicating that the ampersand does suppress the sign.

↑ Back to the top


Keywords: kbdsupport, kbhowto, kbprogramming, kbbillprodsweep, kb

↑ Back to the top

Article Info
Article ID : 138520
Revision : 4
Created on : 6/10/2019
Published on : 6/10/2019
Exists online : False
Views : 235