Announcement

Collapse
No announcement yet.

Currency Data Type Confusion

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Currency Data Type Confusion

    The Printed Manual for PB/DLL 6.0 and the help file for both PBCC and PBDLL indicate that this for the currency data type
    Currency variables are 8-byte binary-coded decimal representations of floating-point numbers, which are considered to always have a fixed number of digits to the right of the decimal point. Currency numbers have a range of approximately 9.99x10^-63 to 9.99x10^63
    But my testing shows that the PBCC 2.0 currency data type matches that of Visual Basic (i.e. a Quad integer with four implied decimal places). Is this the same as BCD? I thought BCD used integers internally for both the mantissa and exponent calculations.

    Code:
    'PowerBasic Console Compiler 2.0 Source Code
    #Dim All
    #Register None
    Type tyCurTest
         q1 As Quad
         c1 As Cur
         x1 As Cux
    End Type
        
    Function PbMain() As Long
        Cls
        Dim rcCurTest As tyCurTest
        Dim nLen As Long
        Dim Fil1 As String
        Dim XF1 As Integer
        
        nLen = Len(rcCurTest)
        Fil1 = "c:\pbcc20\samples\currtest.dat"
        On Error Resume Next
        Kill Fil1
        On Error GoTo 0
        xf1=FreeFile
        Open Fil1 For Random As #XF1 Len=nLen
        rcCurTest.q1 = 123456&&
        rcCurTest.c1 = [email protected]
        rcCurTest.x1 = [email protected]@
        Put #XF1,1,rcCurTest
        
        rcCurTest.q1 = 987654320123&&
        rcCurTest.c1 = [email protected]
        rcCurTest.x1 = [email protected]
        Put #XF1,2,rcCurTest
        Close #XF1
        Print "program done--press any key to finish"
        WaitKey$
        
    End Function
        
    'Visual Basic 4.0/32 Bit Code
    'Project File
        
    Form=FrmMain.frm
    Module=MainProgram; CurVb.bas
    ProjWinSize=44,809,205,264
    ProjWinShow=2
    IconForm="frmMain"
    HelpFile=""
    Title="Test of Currency to Quad Data Types"
    ExeName32="CurVb.exe"
    Path32="c:\pbcc20\samples"
    ExeName="CURVB.EXE"
    Path="c:\pbcc20\samples"
    Name="CurVb"
    HelpContextID="0"
    StartMode=0
    VersionCompatible32="0"
    MajorVer=1
    MinorVer=0
    RevisionVer=0
    AutoIncrementVer=0
    ServerSupportFiles=0
    VersionCompanyName="Joe Murphy Test Code"
        
    'Basic Module
        
    Attribute VB_Name = "MainProgram"
    Option Explicit
        Dim nLen As Long
        Dim Fil1 As String
        Dim XF1 As Integer
    
    Type tyCurTest
        c1 As Currency
        c2 As Currency
        x1 As Long
        x2 As Long
    End Type
    Dim rcCurTest As tyCurTest
    
    Sub Init()
        nLen = Len(rcCurTest)
        Fil1 = "c:\pbcc20\samples\currtest.dat"
        XF1 = FreeFile
        Open Fil1 For Random As #XF1 Len = nLen
    End Sub
    
    Sub MProg()
        Get #XF1, , rcCurTest
        frmMain!lblCur1.Caption = Str$(rcCurTest.c1)
        frmMain!lblCur2.Caption = Str$(rcCurTest.c2)
        frmMain!lblCur3.Caption = Str$(rcCurTest.x1) & Str$(rcCurTest.x2)
        frmMain.Refresh
        DoEvents
    End Sub
    
    Sub QProg()
        Close
        Unload frmMain
        End
    End Sub
        
    ' Form File
        
    
    VERSION 4.00
    Begin VB.Form frmMain 
       BackColor       =   &H00C0C0C0&
       Caption         =   "Test of Currency to Quad Data Types"
       ClientHeight    =   6450
       ClientLeft      =   1170
       ClientTop       =   1800
       ClientWidth     =   9420
       BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
          Name            =   "Arial"
          Size            =   9.75
          Charset         =   0
          Weight          =   400
          Underline       =   0   'False
          Italic          =   0   'False
          Strikethrough   =   0   'False
       EndProperty
       ForeColor       =   &H80000008&
       Height          =   7200
       HelpContextID   =   10
       Left            =   1080
       LinkTopic       =   "Form1"
       ScaleHeight     =   6450
       ScaleWidth      =   9420
       Top             =   1140
       Width           =   9600
       Begin VB.CommandButton cmdStart 
          Caption         =   "&Start"
          Height          =   495
          Left            =   8040
          TabIndex        =   1
          Top             =   120
          Width           =   1215
       End
       Begin VB.CommandButton cmdExit 
          Caption         =   "E&xit"
          Height          =   495
          Left            =   8040
          TabIndex        =   0
          Top             =   840
          Width           =   1215
       End
       Begin VB.Label lblCur3 
          Caption         =   "Label1"
          Height          =   495
          Left            =   240
          TabIndex        =   4
          Top             =   1560
          Width           =   5775
       End
       Begin VB.Label lblCur2 
          Caption         =   "Label1"
          Height          =   495
          Left            =   240
          TabIndex        =   3
          Top             =   840
          Width           =   5775
       End
       Begin VB.Label lblCur1 
          Caption         =   "Label1"
          Height          =   495
          Left            =   240
          TabIndex        =   2
          Top             =   120
          Width           =   5775
       End
       Begin VB.Menu FileMenu 
          Caption         =   "&File"
          Begin VB.Menu FileMenuStart 
             Caption         =   "&Start"
          End
          Begin VB.Menu FileMenuExit 
             Caption         =   "E&xit"
          End
       End
    End
    Attribute VB_Name = "frmMain"
    Attribute VB_Creatable = False
    Attribute VB_Exposed = False
    
    Private Sub cmdExit_Click()
        Call QProg
    End Sub
    
    Private Sub cmdStart_Click()
        Call MProg
    End Sub
    
    Private Sub FileMenuExit_Click()
        Call cmdExit_Click
    End Sub
    
    Private Sub FileMenuStart_Click()
        Call cmdStart_Click
    End Sub
    
    Private Sub Form_Load()
        Call Init
    End Sub
    I do not have PB/DOS still on my computer to check to see if the 32 bit windows version of the currency data type is compatible with the 16 bit DOS Version.
    I hope that someone can help end my confusion.

    Joe Murphy

    ------------------

  • #2
    Unfortunately, the description in the help file is incorrect. Currency is indeed based upon a Quad integer with an implied decimal place.

    The following was "borrowed" from the Documentation Dept:
    Internally, currency numbers are stored as Quad Integers with an implied decimal point (at 2 places for Currency, and at 4 places for Extended Currency). This approach ensures that the exact digits of the variables can be represented exactly.
    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Thanks for the clarification.

      I guess this means that your 'borrowed' quote will make it into the FAQ Help file errata

      Although, it would not affect me, do you know if the PB/DLL 6.0 Currency data type is different from the PB/DOS currency data type.

      Thanks
      Joe

      ------------------

      Comment

      Working...
      X