469,923 Members | 1,597 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

python win32/excel problem

Hi,
*
I have a very simple python win32 example (gleaned from the O'Reilly
book on Win32 programming for Python), of an Excel client with a COM
server. Essentially I have three VB buttons - start_server,
stop_server and test_server. The first two do the obvious, the last
takes inputs from two cells in the excel sheets, then passes them to
the python server which adds them together and returns the result an
Excel message dialog.
*
Everything works just fine, except when I make changes to the python
code. The changes get picked up in Excel, but only when I quit the
entire Excel application. Obviously the COM object is being cached
somewhere*- I am guessing that setting "Server = Nothing" only
overrides the reference, rather than destroying the object instance.
*
Any ideas on how to get VB to pick up a new python instance without
quitting?
*
thanks,
*
Justin
*
<<python>>
*
import pythoncom
import win32com.server.register
*
class simpleServer:
***
*** _public_methods_=['add']
*** _reg_progid_="jhw.simpleServer"
*** _reg_clsid_=str(pythoncom.CreateGuid())
*
*** def add(self,a,b):
******* return a+b
***
if __name__=='__main__':
*** win32com.server.register.UseCommandLine(simpleServ er)
*
<<VB>>
*
Public SimpleServer As Object

Sub start_server()
*** On Error GoTo start_server_error
*** If Not (SimpleServer Is Nothing) Then
******* MsgBox "server already running"
******* Exit Sub
*** End If
*** Set SimpleServer = CreateObject("jhw.simpleServer")
*** MsgBox "server started"
*** Exit Sub
start_server_error:
*** MsgBox "error starting server"
*** End
End Sub

Sub stop_server()
*** If (SimpleServer Is Nothing) Then
******* MsgBox "server not running"
******* Exit Sub
*** End If
*** Set SimpleServer = Nothing
*** MsgBox "server stopped"
End Sub

Sub test_server()
*** On Error GoTo test_server_error
*** Dim a, b, r As Double
*** a = Range("a").Value
*** b = Range("b").Value
*** r = SimpleServer.Add(a, b)
*** MsgBox "result = " & r
*** Exit Sub
test_server_error:
*** MsgBox "error testing server - it's probably not running"
*** End
End Sub
Jul 18 '05 #1
0 1426

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
2 posts views Thread by nvhengr | last post: by
6 posts views Thread by ɽ | last post: by
4 posts views Thread by michael.pearmain | last post: by
3 posts views Thread by Hamilton, William | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.