Microsoft KB Archive/51414

= Internal Format of CURRENCY Data Type in Basic products =

Article ID: 51414

Article Last Modified on 8/16/2005

-

APPLIES TO


 * Microsoft Visual Basic for MS-DOS
 * Microsoft Visual Basic 1.0 Standard Edition
 * Microsoft QuickBasic 4.0
 * Microsoft QuickBASIC 4.0b
 * Microsoft QuickBasic 4.5 for MS-DOS
 * Microsoft BASIC Professional Development System 7.0
 * Microsoft BASIC Professional Development System 7.1

-



This article was previously published under Q51414



SUMMARY
The CURRENCY data type is an 8-byte signed integer scaled by 10,000. This allows a variable of the CURRENCY type to have a range of: (2 ^ 63 -1) / 10,000 =  +922337203685477.5807 To   (2 ^ 63) / 10,000   =  -922337203685477.5808 Up to 19 digits are allowed, with no more than 4 digits to the right of the decimal point.



MORE INFORMATION
Because the CURRENCY type is scaled by 10,000, its internal representation is the actual value multiplied by 10,000. For instance, a CURRENCY variable holding the value 0.0001 will be stored as follows: HIGH BYTE                                                    LOW BYTE 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000001 As with ordinary INTEGERs, the higher byte is stored at the higher memory address so that once you find the address of the variable, you will find the low byte there, the second byte stored above, the third byte above that, etc. The example program listed below displays the hexadecimal machine representation for a CURRENCY data type variable whose value is INPUT from the keyboard.

Sample Code: 'To try this example in VBDOS.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program. ' 'To try this example in VB.EXE: ' 1. From the File menu, choose New Project. ' 2. Copy the code example to Form_Click event procedure. '   (Note: code will have to be slightly changed for VB) ' 3. Press F5 to run the program. ' 4. Click on the Form ' 'To try this example in QB.EXE or QBX.EXE ' 1. From the File menu, choose New Program. ' 2. Copy the code example to the Code window. ' 3. Press F5 to run the program. ' '****************************************************************** '    Sample program to display machine representation of the     * '    CURRENCY data type (8-byte scaled INTEGER)                  * '****************************************************************** CLS DO UNTIL INKEY$ = CHR$(27) PRINT &quot;Enter a CURRENCY value. The machine representation will be &quot; PRINT &quot;displayed in Hex&quot; INPUT a@                  ' &quot;@&quot; is the CURRENCY data type suffix. address% = VARPTR(a@)     ' Get the address of the variable a@.

FOR i% = 7 TO 0 STEP -1 PRINT HEX$(PEEK(address% + i%)); &quot; &quot;;  ' Display representation NEXT i%                                   ' in normal Low-Byte to                                             ' the right form. PRINT PRINT &quot;press a key to continue, Esc to EXIT&quot; SLEEP LOOP

Additional query words: VBmsdos QuickBas BasicCom 1.00 4.00 4.00b 4.50 7.00 7.10

Keywords: KB51414

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.