Announcement

Collapse
No announcement yet.

CURRENCY variables in VB

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

    CURRENCY variables in VB

    It appears that Microsoft has changed how they deal with returning currency variables from a function.

    I have verified the change in VB6. Can someone please compile and call the following function from VB4 and VB5 as well as MS Access?
    Code:
    FUNCTION cTest ALIAS "cTest" () EXPORT AS CURRENCY
      FUNCTION = 1.1@
    END FUNCTION
    Please let me know the results.

    --Dave


    -------------
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Home of the BASIC Gurus
    www.basicguru.com

    #2
    VB5:
    Syntax Error:
    FUNCTION = 1.1@


    ------------------
    Scott
    mailto:[email protected][email protected]</A>
    Scott Turchin
    MCSE, MCP+I
    http://www.tngbbs.com
    ----------------------
    True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

    Comment


      #3
      Dave...

      VB6.0 -911903577068948.2637

      VB5.0 -911903577068948.2637

      VB4.0 2430906824406.2323
      (32bit)


      ------------------
      Jim..
      [email protected]
      Jim..

      Comment


        #4
        I tested in VB6

        Function cTest() As Currency: cTest = 1.1@: End Function
        Private Sub Form_Load(): MsgBox cTest: End: End Sub

        I see 1.1


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

        Comment


          #5
          Guys, the code Dave posted was intended to be compiled into a DLL with PB/DLL, and then called from VB code... I guess that was not very clear.

          Jim seems to have understood... Thanks Jim!

          Can anyone confirm his results with this test?

          ------------------
          Lance
          PowerBASIC Support
          mailto:[email protected][email protected]</A>
          Lance
          mailto:[email protected]

          Comment


            #6
            1) Format of currency in VB6 and PB6 is the same
            2) If to declare in VB6
            Private Declare Function cTest Lib "..." () As Double (!!!)
            it will be correct results.

            PB accepts currency as currency, but returns double instead of currency. Looks, that not Microsoft is wrong.
            Code:
            PB code --
            
            #Compile Dll "G:\1.DLL"
            Function cTest Alias "cTest" (aa As Currency) Export As CURRENCY
              MsgBox Str$(aa), , "From VB"
              Function = -12345678.1567@
            End Function
            
            VB-code --
            
            Private Declare Function cTest Lib "G:\1.DLL" (aa As Currency) As Double
            Private Sub Form_Load()
            MsgBox cTest(1234567890.1234@), , "From PB": End
            End Sub
            [This message has been edited by Semen Matusovski (edited February 29, 2000).]

            Comment


              #7
              Funny enough!

              Declare Function cTest Lib "d:\test.dll" () As Currency
              returns 864559778065278,9875

              Declare Function cTest Lib "d:\test.dll" () As Double
              returns 1,1

              Using VB6, SP3 German Version

              Knuth

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

              Comment


                #8
                Thanks guys!

                VB expects the result to be in EDX:EAX. PowerBASIC returns it on top of the 87 stack.

                Funny thing is that the only documentation Microsoft provides on the subject says that what we're doing is right. However, it's for 16-bit (which is why PB/DLL 2.0 works correctly with currency variables).

                I guess technically it's an official bug in PowerBASIC. However, fixing it may break existing programs, so we'll need to think about this a little bit.

                --Dave


                ------------------
                PowerBASIC Support
                mailto:[email protected][email protected]</A>
                Home of the BASIC Gurus
                www.basicguru.com

                Comment


                  #9
                  I have found that if you dimension a variable of the currency type first, set the variable to the value then set the function from the variable, then the currency function will return the right value. The setting of the function must come from a variable not from a another function or constant ect. Example below.

                  FUNCTION dsCVC(x AS STRING) EXPORT AS CUR
                  DIM cx AS CUR
                  IF LEN(x)<> 8 THEN
                  MSGBOX "Illegal Function Call"
                  FUNCTION = 0
                  ELSE
                  cx =CVCUR(x)
                  FUNCTION = cx
                  END IF
                  END FUNCTION


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

                  Comment

                  Working...
                  X
                  😀
                  🥰
                  🤢
                  😎
                  😡
                  👍
                  👎