ComatePlus use SAFEARRAY with strings

Just starting out? Need help? Post your questions and find answers here.
malo
User
User
Posts: 22
Joined: Mon Sep 28, 2009 5:19 pm

ComatePlus use SAFEARRAY with strings

Post by malo »

Hello

I'm using SAFEARRAY to transfer from a list of tables of numbers to Excel,
this is very fast and works very well.
I also thought of using it to move the chains, because I saw that
element is of type variant, I think my interpretation is not
good.

Exl \ SetProperty ("Range (' "+ laPlage.s + " ') =" + Str (var) + "as variant")

But this does not work, I have numbers instead of strings.
It is there a way to use SAFEARRAY, I know otherwise
Can I use hStatement

Thank you in advance for your answers.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ComatePlus use SAFEARRAY with strings

Post by srod »

Make sure you have a space before the as in "as variant" so use " as variant".

Must admit that I do not understand what you are trying to do? What do you mean by a 'chain' ?
I may look like a mule, but I'm not a complete ass.
malo
User
User
Posts: 22
Joined: Mon Sep 28, 2009 5:19 pm

Re: ComatePlus use SAFEARRAY with strings

Post by malo »

SROD thank you for taking the trouble to reply.

Until now I transmitting values such as: 142,548,5746, etc. ...

I would like if possible because the method is fast SAFEARRAY,
also pass on my Excel sheet value as: "Amount of the month", "amount> to", etc. ..
these values are stored in the list that I call the office needs.

By cons I do not understand your first sentence, and especially the concept of space

Code: Select all

Procedure ListChamps()
VariantClear_(var)
    Dim safeArrayBound.SAFEARRAYBOUND(2)
      With safeArrayBound(0)
        \lLbound = 1
        \cElements = 1
      EndWith
      With safeArrayBound(1)
        \lLbound = 1
        \cElements = column
      EndWith


  ;Now create the array and check for success.
    *safeArray.SAFEARRAY = SafeArrayCreate_(#VT_I4, 2, @safeArrayBound())
    If *safeArray = 0
      MessageRequester("COMate -Excel 2-d Safearray demo!", "Couldn't create the Safearray!")
      End
    EndIf
  
    Dim indices(1)
     i = 1 
       
      ForEach ListChamps()
        indices(0) = i
        indices(1) = j
        temp.s=ListChamps()					;ListChamps préparée par ailleurs
        SafeArrayPutElement_(*safeArray, @indices(), @temp.s)
        j +1
      Next
   
    With var
      \vt = #VT_ARRAY|#VT_I4
      \parray = *safeArray
    EndWith

EndProcedure
I hope that my explanation will be clearer
Thank you in advance
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ComatePlus use SAFEARRAY with strings

Post by srod »

Your code is a right royal mess. You are adding strings (incorrectly) to a safearray of integers!!!

Try the following which shows how to set up a safearray of strings (you have to use BSTRs) :

Code: Select all

Procedure ListChamps()
VariantClear_(var)
    Dim safeArrayBound.SAFEARRAYBOUND(2)
      With safeArrayBound(0)
        \lLbound = 1
        \cElements = 1
      EndWith
      With safeArrayBound(1)
        \lLbound = 1
        \cElements = column
      EndWith


  ;Now create the array and check for success.
    *safeArray.SAFEARRAY = SafeArrayCreate_(#VT_BSTR, 2, @safeArrayBound())
    If *safeArray = 0
      MessageRequester("COMate -Excel 2-d Safearray demo!", "Couldn't create the Safearray!")
      End
    EndIf
  
    Dim indices(1)
     i = 1 
       
      ForEach ListChamps()
        indices(0) = i
        indices(1) = j
        temp=COMate_MakeBSTR(ListChamps())
        SafeArrayPutElement_(*safeArray, @indices(), temp)
        SysFreeString_(temp)
        j +1
      Next
   
    With var
      \vt = #VT_ARRAY|#VT_BSTR
      \parray = *safeArray
    EndWith

EndProcedure
NOTE the use of BSTRs which are the types of strings supported by safearrays.

Now if you wish to add a mix of integers and strings to your safearray then you will need to use an array of variants (#VT_VARIANT).
I may look like a mule, but I'm not a complete ass.
malo
User
User
Posts: 22
Joined: Mon Sep 28, 2009 5:19 pm

Re: ComatePlus use SAFEARRAY with strings

Post by malo »

Actually I knew that this code was incorrect and somewhat to the street, I put it to show the direction of my research.
It seems to me that I had trouble finding this answer .....

THANKS AGAIN FOR THIS ROYAL ANSWER IS EXACTLY WHAT I WANTED.

Between your code and those of KIFFI I could take another step with Excel

ComatePlus is not very easy to understand at first, but gradually as I use Excel I perceive any interest.

Thank you for putting ComatePlus available.

Cordially
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ComatePlus use SAFEARRAY with strings

Post by srod »

There is a good reason for the COMatePLUS manual being as extensive as it is. :wink:

Truth be told though, a lot of people mistake the complexity of the automation object they are working with for the complexity of COMatePLUS. That is, they blame any difficulties they are having with, say, the Excel application object, on COMatePLUS rather than on Excel itself! You must remember that Excel, for example, is far far far more complex than COMatePLUS.
I may look like a mule, but I'm not a complete ass.
malo
User
User
Posts: 22
Joined: Mon Sep 28, 2009 5:19 pm

Re: ComatePlus use SAFEARRAY with strings

Post by malo »

Until I needed ComatePlus for working with Excel, I have not had the opportunity to apply to other object COM.Sans him I could not continue to turn in my VBA application PureBasic;

THANKS AGAIN FOR COMATEPLUS

I will start a new message for the problem that I
in version 4.5 and PureBasic ComatePlus between knowing that
same programe works correctly with 4.31

Cordially
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Re: ComatePlus use SAFEARRAY with strings

Post by srod »

Make sure you are using the version of COMatePLUS which is specific for PB 4.5.
I may look like a mule, but I'm not a complete ass.
Post Reply