473,386 Members | 1,736 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

passing an array of variant in vb to a python COM object = win32com bug ?

vml
I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :

class Fop:
_public_methods_ = [ 'SqVal' ]
def SqVal(self,*val):
#vol=(val[0][0],val[0][1])
#mat1=mat((vol))
#up=linalg.inv(mat1)
return str(val)#up
_reg_verprogid_ = "Python.Fop.3"
_reg_progid_ = "Python.Fop"
_reg_desc_ = "Python Fop"
_reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"

I pass to this method an array of variant which is the matrix to
invert like that:
vb6 code :
Set obj = CreateObject("Python.Fop")
Dim ty(1, 1) As Variant

ty(0, 0) = 1
ty(1, 0) = 2
ty(0, 1) = 3
ty(1, 1) = 4

toto = obj.SqVal(ty)
when I dispaly toto as str(val) I obtain the following tuple "(((1,
3), (2, 4)),)" which is not usable ....

Do you have an idea to explain this strange behaviour ?

thank you !

May 3 '07 #1
5 3969
En Thu, 03 May 2007 04:54:43 -0300, vml <vi***********@gmail.comescribió:
I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :

class Fop:
_public_methods_ = [ 'SqVal' ]
def SqVal(self,*val):
#vol=(val[0][0],val[0][1])
#mat1=mat((vol))
#up=linalg.inv(mat1)
return str(val)#up
_reg_verprogid_ = "Python.Fop.3"
_reg_progid_ = "Python.Fop"
_reg_desc_ = "Python Fop"
_reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"

I pass to this method an array of variant which is the matrix to
invert like that:
vb6 code :
Set obj = CreateObject("Python.Fop")
Dim ty(1, 1) As Variant

ty(0, 0) = 1
ty(1, 0) = 2
ty(0, 1) = 3
ty(1, 1) = 4

toto = obj.SqVal(ty)
when I dispaly toto as str(val) I obtain the following tuple "(((1,
3), (2, 4)),)" which is not usable ....

Do you have an idea to explain this strange behaviour ?
This is the expected behaviour. Writing it completely in Python:

pydef SqVal(*val):
.... return str(val)
....
pyty=((1,3),(2,4))
pySqVal(ty)
'(((1, 3), (2, 4)),)'

The *val parameter receives a tuple, whose elements are the positional
arguments used when calling the function. As you call the function with a
single argument, val receives a tuple with a single element.
Perhaps you want to write it as:

pydef SqVal(val):
.... print val[0][0]
.... print val[0][1]
.... print val[1][0]
.... print val[1][1]
....
pySqVal(ty)
1
3
2
4

(Of course, if used as a Fop method, dont forget the "self" parameter)

--
Gabriel Genellina
May 3 '07 #2
vml
On 3 mai, 14:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Thu, 03 May 2007 04:54:43 -0300, vml <victor.leb...@gmail.comescribió:
I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :
class Fop:
_public_methods_ = [ 'SqVal' ]
def SqVal(self,*val):
#vol=(val[0][0],val[0][1])
#mat1=mat((vol))
#up=linalg.inv(mat1)
return str(val)#up
_reg_verprogid_ = "Python.Fop.3"
_reg_progid_ = "Python.Fop"
_reg_desc_ = "Python Fop"
_reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"
I pass to this method an array of variant which is the matrix to
invert like that:
vb6 code :
Set obj = CreateObject("Python.Fop")
Dim ty(1, 1) As Variant
ty(0, 0) = 1
ty(1, 0) = 2
ty(0, 1) = 3
ty(1, 1) = 4
toto = obj.SqVal(ty)
when I dispaly toto as str(val) I obtain the following tuple "(((1,
3), (2, 4)),)" which is not usable ....
Do you have an idea to explain this strange behaviour ?

This is the expected behaviour. Writing it completely in Python:

pydef SqVal(*val):
... return str(val)
...
pyty=((1,3),(2,4))
pySqVal(ty)
'(((1, 3), (2, 4)),)'

The *val parameter receives a tuple, whose elements are the positional
arguments used when calling the function. As you call the function with a
single argument, val receives a tuple with a single element.
Perhaps you want to write it as:

pydef SqVal(val):
... print val[0][0]
... print val[0][1]
... print val[1][0]
... print val[1][1]
...
pySqVal(ty)
1
3
2
4

(Of course, if used as a Fop method, dont forget the "self" parameter)

--
Gabriel Genellina
I just tried to replace the *val by SqVal(self,val) and call the
method in vb but it crashes down :

"when refilling safe array the sequence must have the same number of
dimension as the existing array"

my python code is now :

def SqVal(self,val):
## volr=[val[0][0][i] for i in range(size(val,2))]
## voli=[val[0][1][i] for i in range(size(val,2))]
## mat1=mat(volr)+1j*mat(voli)
## up=linalg.pinv(mat1)
## out=up.real.tolist()
## out.extend(up.imag.tolist())
return val

By the way Do you have any idea to debug the com server script ? ( I
would like to know if a can access the value in the function while
calling it from vb 6)


tahnks a lot !
May 3 '07 #3
vml wrote:
On 3 mai, 14:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Thu, 03 May 2007 04:54:43 -0300, vml <victor.leb...@gmail.comescribió:
>>I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :
class Fop:
_public_methods_ = [ 'SqVal' ]
def SqVal(self,*val):
#vol=(val[0][0],val[0][1])
#mat1=mat((vol))
#up=linalg.inv(mat1)
return str(val)#up
_reg_verprogid_ = "Python.Fop.3"
_reg_progid_ = "Python.Fop"
_reg_desc_ = "Python Fop"
_reg_clsid_ = "{30BD3490-2632-11cf-AD5B-524153480001}"
I pass to this method an array of variant which is the matrix to
invert like that:
vb6 code :
Set obj = CreateObject("Python.Fop")
Dim ty(1, 1) As Variant
ty(0, 0) = 1
ty(1, 0) = 2
ty(0, 1) = 3
ty(1, 1) = 4
toto = obj.SqVal(ty)
when I dispaly toto as str(val) I obtain the following tuple "(((1,
3), (2, 4)),)" which is not usable ....
Do you have an idea to explain this strange behaviour ?
This is the expected behaviour. Writing it completely in Python:

pydef SqVal(*val):
... return str(val)
...
pyty=((1,3),(2,4))
pySqVal(ty)
'(((1, 3), (2, 4)),)'

The *val parameter receives a tuple, whose elements are the positional
arguments used when calling the function. As you call the function with a
single argument, val receives a tuple with a single element.
Perhaps you want to write it as:

pydef SqVal(val):
... print val[0][0]
... print val[0][1]
... print val[1][0]
... print val[1][1]
...
pySqVal(ty)
1
3
2
4

(Of course, if used as a Fop method, dont forget the "self" parameter)

--
Gabriel Genellina

I just tried to replace the *val by SqVal(self,val) and call the
method in vb but it crashes down :

"when refilling safe array the sequence must have the same number of
dimension as the existing array"

my python code is now :

def SqVal(self,val):
## volr=[val[0][0][i] for i in range(size(val,2))]
## voli=[val[0][1][i] for i in range(size(val,2))]
## mat1=mat(volr)+1j*mat(voli)
## up=linalg.pinv(mat1)
## out=up.real.tolist()
## out.extend(up.imag.tolist())
return val

By the way Do you have any idea to debug the com server script ? ( I
would like to know if a can access the value in the function while
calling it from vb 6)


tahnks a lot !

Debugging COM objects is best done using logging module or at least
writing to a file during processing. You can review the log file
to see what was going on.

-Larry
May 3 '07 #4
En Thu, 03 May 2007 09:41:57 -0300, vml <vi***********@gmail.comescribió:
On 3 mai, 14:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
>En Thu, 03 May 2007 04:54:43 -0300, vml <victor.leb...@gmail.com>
escribió:
I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :
I just tried to replace the *val by SqVal(self,val) and call the
method in vb but it crashes down :

"when refilling safe array the sequence must have the same number of
dimension as the existing array"
That can't happen with your Python code below, so it must be on the
caller. Maybe you wrote something like: xx=something.SqVal(yy) and xx,yy
are declared of different sizes.
def SqVal(self,val):
## ...
return val

By the way Do you have any idea to debug the com server script ? ( I
would like to know if a can access the value in the function while
calling it from vb 6)
Write a log file as suggested, or use OutputDebugString with the DebugView
program from www.sysinternals.com

--
Gabriel Genellina
May 4 '07 #5
vml
On 4 mai, 06:56, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Thu, 03 May 2007 09:41:57 -0300,vml<victor.leb...@gmail.comescribió:
On 3 mai, 14:20, "Gabriel Genellina" <gagsl-...@yahoo.com.arwrote:
En Thu, 03 May 2007 04:54:43 -0300,vml<victor.leb...@gmail.com>
escribió:
I have a python com object which contains a method to inverse an array
in vb 6 the definition of the class is :
I just tried to replace the *val by SqVal(self,val) and call the
method in vb but it crashes down :
"when refilling safe array the sequence must have the same number of
dimension as the existing array"

That can't happen with your Python code below, so it must be on the
caller. Maybe you wrote something like: xx=something.SqVal(yy) and xx,yy
are declared of different sizes.
It is true that I call the python routine like that in vb :
toto = obj.SqVal(ty)

If I am understanding well I need to pass an array of 2x2 and I should
retireve an array of variant of 2x2 ....

I tried to do that :
vb6 :

Dim obj As Object
Dim toto(1, 1, 2) As Variant

Set obj = CreateObject("Python.Fop")
Dim ty(1, 1, 2) As Variant

ty(0, 0, 0) = 1
ty(0, 1, 0) = 2
ty(0, 0, 1) = 3
ty(0, 0, 2) = 7
ty(0, 1, 1) = 4
ty(0, 1, 2) = 45

ty(1, 0, 0) = 1
ty(1, 1, 0) = 2
ty(1, 0, 1) = 3
ty(1, 0, 2) = 7
ty(1, 1, 1) = 4
ty(1, 1, 2) = 45

toto = obj.SqVal(ty)

but it is saying that the compiler can not assign the array toto at
the line toto=obj.SqVal().... hum strange .....

any ideas ?
Thank you for your help !

def SqVal(self,val):
## ...
return val
By the way Do you have any idea to debug the com server script ? ( I
would like to know if a can access the value in the function while
calling it from vb 6)

Write a log file as suggested, or use OutputDebugString with the DebugView
program fromwww.sysinternals.com

--
Gabriel Genellina

May 4 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Matt Smith | last post by:
Hi, all. Just a quick question, when setting a COM process to read a value from a pre-defined register index, I think, I have to change the variable that the value will be returned to (as I have...
0
by: Dave | last post by:
I have been trying an example from the Python Programming on Win32 book on the lastest versions of python (2.3.3) and win32all (build 163). I create the COM object and try to call it from VB but i...
3
by: Annie | last post by:
I am trying to call a COM object which expects a variant datatype to be passed in to the COM API object. However, I get "<COMObject <unknown>>" and the program fails. Below is my code in Python,...
2
by: Raoul | last post by:
I wrote a COM server object in C++ a few months ago. I can use it from Visual Basic, Visual C++, S-Plus and a number of other scripting environments. What I can't do is use it with my FAVOURITE...
0
by: mb3242 | last post by:
Hello, I'm trying to use win32com to call a method in a COM object. I'm having a problem with Python choosing the wrong type when wrapping up lists into VARIANTs. The function I'm trying to call...
2
by: Ken Layton | last post by:
Attempting to pass a VBScript Array of Bytes to a C# Managed COM object has resulted in some very undesirable and strange behavior. When definining a method in my C# COM class as "void Write(byte...
3
by: Mark | last post by:
Hi From what I understand, you can pass arrays from classic ASP to .NET using interop, but you have to change the type of the.NET parameter to object. This seems to be because classic ASP passes...
0
by: dwinson | last post by:
I am writing an add-in in C# for a server written in VB6. In order for my add-in to work I need to implement this method: MyMethod(string inputData) .... so my C# code looks like this: ...
6
by: Rafe | last post by:
Forgive me if I mangle any terminology here, but please correct me if I do... I have an object which acts exactly like a string as long as I stay in Python land. However, I am using the object...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.