Python COM Variant problem
Roger Upole
rupole at hotmail.com
Sun Feb 29 23:40:41 EST 2004
Normally if you've run makepy, the support should be invoked automatically
when you create an instance. What do you get back when you use
win32com.client.gencache.EnsureDispatch ?
Roger
"Annie" <aichia77 at yahoo.com> wrote in message
news:b9942658.0402291633.542752e0 at posting.google.com...
> hi Roger,
> 10s for replying..
> i do running the makepy on that typelib. but can u pls teach me on
> how to include to my Python program??
> 10s in advance
>
>
> "Roger Upole" <rupole at hotmail.com> wrote in message
news:<4040de8f_1 at 127.0.0.1>...
> > 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