Help with COM example from the PPWin32 book

Steve Holden sholden at holdenweb.com
Tue Dec 4 08:46:54 EST 2001


"Will Ganz" <wganz at texoma.net> wrote ...
> Platform:
> Windows 98SE, Excel2000, PythonWin 2.1.1 (#20, Jul 26 2001, 11:38:51)
> HP-6648C(K6-2 550 w/192megs RAM, 20gig hd w/11gig free)
>
> Problem:
> The COM example on pages 68/69 from the 'caiman' book doesnt work. Gives a
> error of 438 when VBA code from Excel is executed.
>
> Discussion:
> >>>>>> SimpleCOMServer.py <<<<<<<<<<<<<<
> #simple COM Server demo
>
> class PythonUtilities:
>     _public_methods_ = [ 'SplitString' ]
>     _reg_progid_ = "PythonDemos.Utilities"
>     _reg_clsid_ = "{B91A4120-E716-11D5-9D0B-FFFFFF000000}"
>
> def SplitString( self, val, item=None ):
>     import string
>     if item != None: item = str(item)
>     return string.split(str(val), item)
>
> if __name__ == '__main__':
>     print "Registering COM server . . . . . . . ."
>     import win32com.server.register
>     win32com.server.register.UseCommandLine(PythonUtilities)
>
> Invoked with c:\>python SimpleCOMServer.py
> Output:
> Registering COM server . . . . . . . .
> Registered: PythonDemos.Utilities
>
> In PythonWin Editor goto
> Tools
> COM browser
> Registered Categories
> Python COM Server
> IID: PythonDemos.Utilities, double click to get
> {B91A4120-E716-11D5-9D0B-FFFFFF000000}
>
> So, I know that this is registered. Right??
>
> In Excel's VBA Editor the following code is entered
>
> Sub TestPython()
>
> Set PyUtil = CreateObject("PythonDemos.Utilities")
> response = PyUtil.SplitString("Hello from Python")
>
> For Each Item In response
>     MsgBox Item
> Next
>
> End Sub
>
> Invoked by clicking on the Run button on the toolbar and it gives an error
> of,
>
> Run-time error '438'
> Object doesn't support this property or method
>
> When Debug is clicked, the yellow highlight is on this line:
>
> response = PyUtil.SplitString("Hello from Python")
>
> Yes, I have RTFM, RTFFAQ, STFA(Searched the archive), BMFB(Bought more
> books), RTFT(Read those too), used Google, looked at Mark Hammond's site &
> looked at his ppt files, and all to no avail.
>
> Does anyone know what is going on here??

If you look more carefully at the Python source in the book you will notice
that the SplitString method is not indented far enough. This makes it a
function in the main program rather than a method of class PythonUtilities.

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list