Announcement

Collapse
No announcement yet.

Workaround for CVCUR

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

  • Workaround for CVCUR

    Hello All,

    I have a database in PBWIN and one of the fields is a Currency variable made with MKCUR$

    I need to add the CVCUR fuction to an old PB Dos program.

    Can anyone tell me the manual way to do this so I can add it to my DOS program?

  • #2
    The PB/Windows CURRENCY is actually a scaled 64-bit binary integer with four implied decimals. (This is documented so you are not going off the reservation here).

    So in your PB/DOS program you can treat the 8 bytes as a QUAD as long as you divide by 10,000.

    Oops, is QUAD supported by PB/DOS? Let me look... yes, it is, so this will work.

    You can write your own function:
    Code:
    FUNCTION CVCUR (cur$) AS FIX 
    LOCAL pQ AS QUAD PTR
              pQ = STRPTR32(Cur$)  ' point at eight-byte string
      FUNCTION = @pQ / [email protected]  ' divide apparent value by 10,000  
                                             ' to allow for the implied decimals
    END FUNCTION
    Something like that, anyway....

    MCM
    Michael Mattias
    Tal Systems Inc. (retired)
    Racine WI USA
    [email protected]
    http://www.talsystems.com

    Comment


    • #3
      I couldn't get that to compile so I changed it to this. However it returns incorrect values?

      Code:
      Function CVCUR (cur$) As Fix
      '
      Dim pQ As QUAD Ptr
      '
      pQ = STRPTR32(Cur$)  ' point at eight-byte string
       Function = pQ / [email protected]  ' divide apparent value by 10,000  
                                          ' to allow for the implied decimals
      End Function

      Comment


      • #4
        Well, your example will never work. pq is a Pointer not a value.

        What was the compile error?

        Note if CVCUR is already a valid PB/DOS function you are going to have to rename it.
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          Function = @pq / 10000

          Comment


          • #6
            >Function = @pq / 10000

            ???

            Can't cast 10000 as FIX here? (Not that my PB/DOS skills are still anywhere near 100%)

            Come to think of it, that is pretty dumb to cast it as fix at this point. Better I think I should have....
            Code:
              FUNCTION =  CFIX(@pq/10000&&)
            ..so there is no type conversion required in the division at all.

            Oh, well, as long as this works, I guess all's well which ends well.
            Michael Mattias
            Tal Systems Inc. (retired)
            Racine WI USA
            [email protected]
            http://www.talsystems.com

            Comment


            • #7
              Final Function

              Code:
              FUNCTION CVCUR(cur$) as FIX
              '
               Dim pQ As Local QUAD Ptr
               pQ = STRPTR32(cur$)           ' point at eight-byte string
              Function = @pQ / [email protected]    ' divide apparent value by 10,000 to allow for the implied decimals
              '
              END FUNCTION

              Comment

              Working...
              X