[python-win32] empty variants

M Shah Din msdin@rpoptions.com
02 Jul 2002 16:39:02 -0700


Hi,

I need to pass an empty variant to a COM objects method but I can't
figure out how to do it.  I asked the same question a while ago, but the
proposed solution did not work.  I have some more details now...

The COM object has a method that looks like this:

------------------------------------------------------------------

Public Sub Foo(ByRef myVariant as Variant, ByRef param1 as String)

	Dim my_flag as Boolean

	If IsEmpty(myVariant) Then
		my_flag = True
	Else
	    If myVariant Is Nothing Then
		my_flag = True
	    Else
		my_flag = False
	    End If
	End If

	If my_flag = True Then
		Set myVariant = CreateObject("some_object")
	End If

	myVariant.SomeMethod()

End Sub

------------------------------------------------------------------

When I call it from python, the my_flag variable is never True.  If I
pass in None for myVariant, the VB debugger shows it as being Null.  If
I pass in pythoncom.Empty, the VB debugger shows it as being Missing. 
It works fine if I call it from a VB method and just dim the variant
without setting it to anything.  How can I pass an empty or nothing
variant from python?

I am using ActiveState ActivePython 2.2 on Win2k.

Thanks,
Shah