Announcement

Collapse
No announcement yet.

Workaround for CVCUR

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

  • Steve Bouffe
    replied
    Final Function

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

    Leave a comment:


  • Michael Mattias
    replied
    >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.

    Leave a comment:


  • Bob Zale
    replied
    Function = @pq / 10000

    Leave a comment:


  • Michael Mattias
    replied
    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.

    Leave a comment:


  • Steve Bouffe
    replied
    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 / 10000@  ' divide apparent value by 10,000  
                                        ' to allow for the implied decimals
    End Function

    Leave a comment:


  • Michael Mattias
    replied
    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 / 10000@  ' divide apparent value by 10,000  
                                             ' to allow for the implied decimals
    END FUNCTION
    Something like that, anyway....

    MCM

    Leave a comment:


  • Steve Bouffe
    started a topic Workaround for CVCUR

    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?
Working...
X
😀
🥰
🤢
😎
😡
👍
👎