Page 1 of 1
ComatePlus use SAFEARRAY with strings
Posted: Sat Apr 17, 2010 9:28 am
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.
Re: ComatePlus use SAFEARRAY with strings
Posted: Sat Apr 17, 2010 10:11 am
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' ?
Re: ComatePlus use SAFEARRAY with strings
Posted: Sat Apr 17, 2010 1:04 pm
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
Re: ComatePlus use SAFEARRAY with strings
Posted: Sat Apr 17, 2010 1:23 pm
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).
Re: ComatePlus use SAFEARRAY with strings
Posted: Sun Apr 18, 2010 8:03 pm
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
Re: ComatePlus use SAFEARRAY with strings
Posted: Mon Apr 19, 2010 10:18 am
by srod
There is a good reason for the COMatePLUS manual being as extensive as it is.
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.
Re: ComatePlus use SAFEARRAY with strings
Posted: Mon Apr 19, 2010 6:50 pm
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
Re: ComatePlus use SAFEARRAY with strings
Posted: Mon Apr 19, 2010 6:53 pm
by srod
Make sure you are using the version of COMatePLUS which is specific for PB 4.5.