2 Replies Last post: Aug 12, 2005 5:06 PM by josue cruz  
josue cruz   35 posts since
Apr 24, 2006
Currently Being Moderated

Aug 4, 2005 4:37 AM

Manipulating Arrays

HI...

 

   1) That's example is to undestand de Arrays parameters

   2) The array that i am build is a ByRef parameter that i need to recover

 

   - DLL CODE

 

        Public Function exampleFunction( ByRef myArray As Variant)

 

                Dim myArray(7,1) as Variant // 8 rows and 1 col

 

                myArray(0,0) = "string0"

                myArray(1,0) = "string1"

                myArray(2,0) = "string2"

                myArray(3,0) = "string3"

                myArray(4,0) = "string4"

                myArray(5,0) = "string5"

                myArray(6,0) = "string6"

        End Function

 

    -- IN Java Code

 

          public static void main(String args[]){

 

              ComFunctions.coInitialize();

              Class1 comTest = Class1.create(ClsCtx.LOCALSERVER);

 

               // SafeArray sa  -


   SafeArray ?????? what is the declaration

 

              Variant param = comTest.exampleFunction( sa ) ;

 

              // And How do  recover a Safe Array ??

 

          }

 

Summary

  1-   I need to know how to declare a SafeArray to pass to the function

  2-   How do Recover the safe array with the values that change in the function

 

THNKS A LOT FOR THIS DUDE.. and the others

Serge Piletsky TeamDev Ltd. 670 posts since
Apr 24, 2006
Currently Being Moderated
1. Aug 4, 2005 2:01 PM in response to: josue cruz
Re: Manipulating Arrays

1. You just need to instantiate the SafeArray parameter on the Java side and it will be initialized in your exampleFunction:

 

  SafeArray sa = new SafeArray();

  comTest.exampleFunction(sa);

 

2. After this function call you can get the dimensions of the retuned SafeArray parameter using its getDimensions() function:

 

  int dims = sa.getDimensions();

 

and number of elements in each dimension, using the sa.getCount(int dim) function:

 

  int numberOfElementsInFirstDimension = sa.getCount(0);

  int numberOfElementsInSecondDimension = sa.getCount(1);

  // and so on

 

Then, after you got the number of dimensions and number of elements in each dimension, you can easily get an element from the array, using its get(int[] indices) function:

 

  BStr element00 = (BStr)sa.get(new int[] {0, 0});

  BStr element60 = (BStr)sa.get(new int[] {6, 0});

More Like This

  • Retrieving data ...