Python COM Variant problem

Roger Upole rupole at hotmail.com
Sat Feb 28 22:48:08 CET 2004


Try running makepy on the typelib that contains the objects.
Also, the actual error msg that if fails with would be helpful.
       Roger

"Annie" <aichia77 at yahoo.com> wrote in message
news:b9942658.0402270131.624a8492 at posting.google.com...
> 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, and the same code in VB which is working
> fine...
>
> I guess this is a variant problem with python? How can I make this
> work? Would appreciate if someone can guide me as I am a python
> newbie... :-)
>
> Thanks very much...
>
> ##In Python
> def setAddOnValue(oBusObj
>     oAddOns = oBusObj.AddOns
>     print oAddOns #returns "<COMObject <unknown>>"
>     print oAddOns.Count #return 3
>     for x in range(1, oAddOns.Count):
>         oAddOn = oAddOns.Item(x) #expects variant datatype for the x
> variable
>
>
>
> ##In VB
> Public Function setAddOnValue(oBusObj As Variant, strAddOnLabel As
> String, strPropLabel As String, oVal As Variant) As Boolean
>     Dim x, y
>     Dim oAddOns As CAddOns
>     Dim oAddOn As CAddOn
>     Dim oAddOnValues As CAddOnValues
>     Dim oAddOnValue As CAddOnValue
>
>     setAddOnValue = False
>     Set oAddOns = oBusObj.AddOns
>
>     For x = 1 To oAddOns.Count
>         Set oAddOn = oAddOns.Item(x)
>         If oAddOn.AddOnName = strAddOnLabel Then
>             Set oAddOnValues = oAddOn.AddOnValues
>             For y = 1 To oAddOnValues.Count
>                 Set oAddOnValue = oAddOnValues.Item(y)
>                 If oAddOnValue.PropertyLabel = strPropLabel Then
>                     setAddOnValue = True
>                     Set oAddOnValue.Data = oVal
>                     Exit For
>                 End If
>             Next y
>         End If
>         If setAddOnValue = True Then
>             Exit For
>         End If
>     Next x
> End Function





More information about the Python-list mailing list