Announcement

Collapse
No announcement yet.

Strings DLLs and Excel spreadsheets

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

  • Strings DLLs and Excel spreadsheets

    Does anyone have experience passing strings to and
    returning strings from Excel Spreadsheets?

    After creating VB Declare Function statements,
    the DLL functions are available to the spreadsheet, but
    Excel passes and receives 'Rubbish' from the function.

    In contrast, the function works fine from the Immediate window
    of VBA inside Excel.

    There seems to be a difference between the VBA to DLL
    'connection' and the Spreadsheet to DLL 'connection'.

    Ideas?

    Thanks

    David

    EXAMPLE:

    In VBA Module:
    Declare Function sdMJDx Lib "sdsun.dll" Alias "sdMJDx" (ByVal Yearx As Long, ByVal Month As Long, ByVal Day As Double, ByVal Hour As Double, ByVal Minute As Double, ByVal Sec As Double, ByVal TimeZone As Double) As String
    IN PB DLL
    Function sdMJDx Alias "sdMJDx" (ByVal Year As Long, ByVal Month As Long, ByVal Day As Double, ByVal Hour As Double, ByVal Minute As Double, ByVal Sec As Double, ByVal TimeZone As Double) Export As String

    Works fine in VBA but return's rubbish from a worksheet.

  • #2
    David,
    First hav eyou declared your function as Public ?
    If you want to stick with your orginal DLL you may try to wrap the DLL declared function within a userdefined function within a VBA module.
    Ex. Public Function NewFunc(Byval ..., byval ) as string
    Dim Retstring as string
    Retstring = sdMJDx(..,....,....)
    NewFunc= Retstring

    end function

    If you want make a function(PB DLL) that trule speaks with Excel take a look at my usersubmitted(in Powerbasic Archives) excel32api.zip
    file


    Regards Eigil


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

    Comment


    • #3
      Yes on both counts. A related question. Do I aslo need to do the
      copy of function parameters that are strings? eg.

      Public Function NewFunc(Byval name as string, ..., byval ) as string
      Dim Retstring as string
      Dim parmstring as string
      parmstring = name
      Retstring = sdMJDx(parmstring,....,....)
      NewFunc= Retstring

      end function

      or will this do?

      Public Function NewFunc(Byval name as string, ..., byval ) as string
      Dim Retstring as string
      Retstring = sdMJDx(name,....,....)
      NewFunc= Retstring

      end function


      Originally posted by E Dingsor:
      David,
      First hav eyou declared your function as Public ?
      If you want to stick with your orginal DLL you may try to wrap the DLL declared function within a userdefined function within a VBA module.
      Ex. Public Function NewFunc(Byval ..., byval ) as string
      Dim Retstring as string
      Retstring = sdMJDx(..,....,....)
      NewFunc= Retstring

      end function

      If you want make a function(PB DLL) that trule speaks with Excel take a look at my usersubmitted(in Powerbasic Archives) excel32api.zip
      file


      Regards Eigil




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

      Comment


      • #4
        David,
        I don't think you have to "copy" the strings to other string variables within the function in the VBA module. It's been a long while since I used PB DLLs and VBA modules to create userdefined functions. Now I only make function with the OPER and XLOPER parameter types.
        I have scanned some old files and I think you have to do the following:
        Declare string parameters in your DLL as ASCIIZ ex. Function newFunc(zNewString AS ASCIIZ,......)
        In your declare section in the VBA module declare the asciiz strings as BYVAL String.

        I think that will do the trick.

        Regards

        Eigil

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

        Comment

        Working...
        X