Python COM Variant problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Annie

    Python COM Variant problem

    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(o BusObj
    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(o BusObj 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.AddOnNam e = strAddOnLabel Then
    Set oAddOnValues = oAddOn.AddOnVal ues
    For y = 1 To oAddOnValues.Co unt
    Set oAddOnValue = oAddOnValues.It em(y)
    If oAddOnValue.Pro pertyLabel = strPropLabel Then
    setAddOnValue = True
    Set oAddOnValue.Dat a = oVal
    Exit For
    End If
    Next y
    End If
    If setAddOnValue = True Then
    Exit For
    End If
    Next x
    End Function
  • Roger Upole

    #2
    Re: Python COM Variant problem

    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@yahoo .com> wrote in message
    news:b9942658.0 402270131.624a8 492@posting.goo gle.com...[color=blue]
    > 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(o BusObj
    > 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(o BusObj 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.AddOnNam e = strAddOnLabel Then
    > Set oAddOnValues = oAddOn.AddOnVal ues
    > For y = 1 To oAddOnValues.Co unt
    > Set oAddOnValue = oAddOnValues.It em(y)
    > If oAddOnValue.Pro pertyLabel = strPropLabel Then
    > setAddOnValue = True
    > Set oAddOnValue.Dat a = oVal
    > Exit For
    > End If
    > Next y
    > End If
    > If setAddOnValue = True Then
    > Exit For
    > End If
    > Next x
    > End Function[/color]


    Comment

    • Annie

      #3
      Re: Python COM Variant problem

      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@hotmail .com> wrote in message news:<4040de8f_ 1@127.0.0.1>...[color=blue]
      > 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@yahoo .com> wrote in message
      > news:b9942658.0 402270131.624a8 492@posting.goo gle.com...[color=green]
      > > 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(o BusObj
      > > 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(o BusObj 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.AddOnNam e = strAddOnLabel Then
      > > Set oAddOnValues = oAddOn.AddOnVal ues
      > > For y = 1 To oAddOnValues.Co unt
      > > Set oAddOnValue = oAddOnValues.It em(y)
      > > If oAddOnValue.Pro pertyLabel = strPropLabel Then
      > > setAddOnValue = True
      > > Set oAddOnValue.Dat a = oVal
      > > Exit For
      > > End If
      > > Next y
      > > End If
      > > If setAddOnValue = True Then
      > > Exit For
      > > End If
      > > Next x
      > > End Function[/color][/color]

      Comment

      • Roger Upole

        #4
        Re: Python COM Variant problem

        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.Ensur eDispatch ?
        Roger

        "Annie" <aichia77@yahoo .com> wrote in message
        news:b9942658.0 402291633.54275 2e0@posting.goo gle.com...[color=blue]
        > 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@hotmail .com> wrote in message[/color]
        news:<4040de8f_ 1@127.0.0.1>...[color=blue][color=green]
        > > 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@yahoo .com> wrote in message
        > > news:b9942658.0 402270131.624a8 492@posting.goo gle.com...[color=darkred]
        > > > 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(o BusObj
        > > > 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(o BusObj 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.AddOnNam e = strAddOnLabel Then
        > > > Set oAddOnValues = oAddOn.AddOnVal ues
        > > > For y = 1 To oAddOnValues.Co unt
        > > > Set oAddOnValue = oAddOnValues.It em(y)
        > > > If oAddOnValue.Pro pertyLabel = strPropLabel Then
        > > > setAddOnValue = True
        > > > Set oAddOnValue.Dat a = oVal
        > > > Exit For
        > > > End If
        > > > Next y
        > > > End If
        > > > If setAddOnValue = True Then
        > > > Exit For
        > > > End If
        > > > Next x
        > > > End Function[/color][/color][/color]


        Comment

        Working...