Ok, I'm about 90% there now<br><br>I've used the Simple.py from page 213, because there is less involved.<br>when I run it- I see the registration messages. All is good so far.<br>I made one tiny change, related to the call to CreateGuid()
<br><br>import pythoncom<br><br>class PythonCOMServer:<br><br> _public_methods_ = ['pyCOMSplit']<br> _reg_progid_= "PythonCOMDemo"<br> _reg_clsid_= pythoncom.CreateGuid()<br><br> def pyCOMSplit(StringFromVB):
<br> from string import split<br> if self.StringFromVB != None:<br> return split(self.StringFromVB )<br><br><br>if __name__ == '__main__':<br> print"Registering COM server"<br> import win32com.server.register
<br> win32com.server.register.UseCommandLine( PythonCOMServer ) <br><br><br>When I try sending a string from the VB side, <br>Type Error; str() takes at most 1 arguments, two given<br><br>I see no explicit calls to str.
<br><br><br>Here's the VB side<br><br><br>Option Explicit<br><br>Private Sub cmdToPython_Click()<br><br> <br> Dim Python As Object<br> Dim FromPython As Variant<br> <br> Set Python = CreateObject("PythonCOMDemo")
<br> <br> FromPython = Python.pyCOMSplit("This string to Python")<br><br> txtFromPython = FromPython<br> <br>End Sub<br><br><br>This call, is what is causing the runtime exception<br>Python.pyCOMSplit
("This string to Python")<br><br><br>What am I doing wrong?<br><br>thanks<br><br><br><br><br><br><br><br><div><span class="gmail_quote">On 12/6/05, <b class="gmail_sendername">Mark Hammond</b> <<a href="mailto:mhammond@skippinet.com.au">
mhammond@skippinet.com.au</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">> >>Certainly COM would work. In this case your VB EXE would use
<br>CreateObject<br>> >>to create a Python implemented object.<br><br>> As what type of Python Object?<br><br>> I have the VB6 ide open, and the references Browser as well,<br>> there is no generic Python object to include into a VB project.
<br><br>> Which means one would have to create a Python COM server<br>> and Type library first, before being able to reference it<br>> from the VB IDE.<br><br>Actually, you don't need to create a typelib. Just register the PythonCOM
<br>server, and have VB use CreateObject with the ProgID. All vars will need to<br>be declared as "object", and you wont get auto-complete type features, but<br>it will work. VB supports late-binding.<br><br><br>
> Even though I have Python Programming in Win32, I'm not sure what<br>> needs to be done to make a minimal Python COM server that can be<br>> called from VB.<br><br>Pages 221 and 222 have an example using VBA (ie, the VB embedded in MSOffice
<br>apps)<br><br>> Also, creating a type library requires using Visual C- which isn't a<br>> problem, it's the language of the IDL required to create the TLB that<br>> I don't udnerstand.<br><br>You should be able to avoid TLBs - certainly to get started...
<br><br>Mark<br><br></blockquote></div><br>