Announcement

Collapse
No announcement yet.

Powerbasic and Lotus Notes (LotusScript) and StringArrays

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

  • Powerbasic and Lotus Notes (LotusScript) and StringArrays

    Hi all !

    I am currently working on a project, where it would save a
    LOT of time if we could use the Sort command on an array of strings
    from LotusScript.

    I have no trouble with the example supplied for VisualBasic, but
    when trying the same in LotusScript, i get an Application Error in
    Lotus Notes.

    As far as I know, Visual Basic stores string-arrays as UNICODE format
    (2 bytes pr. character), and the vbApi32.inc converts these strings to
    ANSI format.

    Lotus uses LMBCS (Lotus Multi-Byte Character Set) to represent their
    strings, and (As far as i know) these are also 2-bytes characters.

    I get the array from Notes to the PB-dll allrigt, but when conver-
    ting the characters, somthing goes wrong, and I am not skilled
    enough in PB to be able to tell, what it is.

    When sorting an Integer-array, there are no problems ;-)

    I hope, that someone out there can help me !


    Cheers,

    Kenneth

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

  • #2
    Kenneth--

    If you can't solve your problem the 'correct' way, then try to
    use a temporary text-file: PB writes the sorted data to the
    text-file and LotusScript opens the text-files and reads the data.
    I don't think it will slow down the procedure that much.

    Regards
    Peter

    P.S.
    Hyggeligt at møde en dansker her. Det sker næsten aldrig!

    ------------------
    [email protected]
    www.dreammodel.dk

    Comment


    • #3
      Hi Peter !

      I have thought about that possibility, and it may end up with, that
      I have to use that one. I would like to check though, if there
      were no chances to use the DLL and Sort function "standard" first.

      (One declare-statement, and one call from my LotusScript - I don't think
      that it gets any easier ;-))

      Cheers, Kenneth


      PS: Ja, det er sjældent man ser andre danskere herude ! - hvis det er,
      så kan du fange mig på [email protected]

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

      Comment


      • #4
        kenneth --

        here are some links (that you properly allready know):
        link 1
        link 2
        link 3

        regards
        peter

        p.s. min mail er psp.dst.dk

        ------------------
        [email protected]
        www.dreammodel.dk

        Comment


        • #5
          Thanks Peter for the Links - I have read through them all, but I
          tried the examples one more time (as they are, and with changes !),
          but not succesfully ;-(

          It is the question, if there is anything to do but use the
          TextFile-approach.

          After - yet another - study of the Lotus Design Help File under
          C-functions and Calls, the following statements occured:

          ---

          Array:

          A 4-byte pointer to the array stored in the LotusScript
          internal array format

          ---

          Passing arrays as arguments:

          Because LotusScript stores an array in a private format, you can
          pass an array by reference to a C function only if the function
          is specifically written for LotusScript. The following example
          shows how to declare and implement a C function that takes a
          LotusScript array of long values.

          In LotusScript:
          Declare Function LSArrayArg Lib "MYDLL" (ArrLng () As Long)_
          As Long
          Dim MyArr(0 to 5) As Long
          Print LSArrayArg(MyArr)

          In C:
          long C_CALL_TYPE LSArrayArg(LSsValueArray *pLSArr)
          {
          long *pData=pLSArr->Data;
          //pData points to first array element
          return pData[0]+pData[1]; //Sum first 2 array elements
          }

          Or:

          long C_CALL_TYPE LSArrayArg(long **pLSArr)
          {
          long *pData=*pLSArr;
          //pData points to first array element
          return pData[0]+pData[1]; //Sum first 2 array elements


          ---------

          I do not have the skills to re-programme the VbApi32.inc file, so
          that it can be used for LotusScript arrays too, and I got to admit,
          that I am a bit confused as to where I start, and where I will end ;-)

          Cheers, Kenneth

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

          Comment


          • #6
            Kenneth--

            I have tried to translate the functions:
            To translate the first example you need to know the LSsValueArray type.
            It looks something like:
            Code:
            type LSsValueArray
                ...
                Data as dword
                ....
            end type
            Let's assume that the LSsValueArray-type is well-defined. Then the function should
            look something like this:
            Code:
            function LSArrayArg(byval lp as dword) export as long
             
                local pLSArr as LSsValueArray ptr
                local pData as long ptr
             
                pLSArr = lp
                pData = @pLSArr.Data
             
                function = @pData[0] + @pData[1]
             
            end function
            The second example is more streight foreward. I would prefer it as you do not
            need the LSsValueArray-type
            Code:
            function LSArrayArg(byval lp as dword) export as long
             
                local pdw as dword ptr
                local pData as long ptr
             
                pdw = lp
                pData = @pdw
             
                function = @pData[0] + @pData[1]
             
            end function
            As far as I know, the PB-array is a pointer to a pointer. You should therefore
            try this (it will properly not work):
            Code:
            function LSArrayArg(LSArr() as long) export as long
             
                function = LSArr(0) + LSArr(1)
             
            end function
            Actually, I don't think you should try to do functions like this:
            Code:
            Declare Function LSArrayArg Lib "MYDLL" (ArrLng () As Long) As Long
            It may be possible, but it implies that you have to have a very well understanding
            of the functioning of a Lotus-array.

            A much simpler approch is this:
            Code:
            Declare Function LSArrayArg Lib "MYDLL" (FirstElement as long, NumberOfElements as long) As Long
            with the dll-function:
            Code:
            Function LSArrayArg (FirstElement as long, NumberOfElements as long) export As Long
             
                dim DataArray(NumberOfElements) as long at varptr(FirstElement)
             
                function = DataArray(0) + DataArray(0)
             
            end function

            Regards
            Peter



            [This message has been edited by Peter P Stephensen (edited November 04, 2000).]
            [email protected]
            www.dreammodel.dk

            Comment


            • #7
              Hi Peter.

              Thank you very much for your help !! - I finally figured it out..
              (after spending nearly 30 hours this saturday and sunday).

              It turns out, that there is a bug i the Lotus Notes IDE, so values
              in an array manipulated by Powerbasic (or any other language, for
              that matter) are NOT shown correctly when returning from the DLL.

              It showed the first 33 entries of the array correct (aside from
              entry number 4, that only showed half the entry - go figure :-),
              and all the remaining elements of the array as empty values !.

              When trying to actually show elements from the array, everything
              went OK, and all the values were present, and in "good shape" :-)

              To say, that PB is fast is an understatement !!! - it would be more
              precise to say, that it "blowed the top off of Lotus Notes". I had
              the following results, when timing (appr.) the ACTUAL sorting.
              (And not including the DLL call, and the initialization of the
              LotusScript Array):

              (This on a PIII, 300mhz with 192Mb of ram)

              Sorting an array with 4600 string-entries : appr. 0,085 sec.
              Sorting an array with 460.000 string-entries: appr. 8,5 sec.
              Sorting an array with 920.000 string-entries: appr. 17 sec. (!!)

              (I stopped at 920.000 entries, because it took too long for Lotus
              to "export" all the arrays to the DLL - appr. 3,5 minutes for
              2000+ individual arrays, that were combined into one single PB-array)

              Once again - Amazing !!!!!

              Thank you very much for your help !

              Kenneth

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

              Comment

              Working...
              X