Hi all,<br>I'm a Python beginner and trying to run the codes from Chapter 5 of Python pramming on win32. But when I tested the COM object with VBA, I got an error msg saying runtime error 438. Is there anyone can help me out? Thanks in advance!<br>
<br>Here are the codes:<br>[Python]<br><span style="font-family: courier new,monospace;">class PythonUtilities:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> _public_methods_ = [ 'SplitString' ]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> _reg_progid_ = "PythonDemos.Utilities"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> _reg_clsid_ = "{D81903FB-62F2-4FB1-993E-63CAF4C963A0}"</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">def SplitString(self, val, item=None):</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> import string</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if item != Nome: item = str(item)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return string.split(str(val), item) </span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">if __name__=='__main__':</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> print "Registering COM server..."</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> import win32com.server.register</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> win32com.server.register.UseCommandLine(PythonUtilities)<br>
<br></span>After running above scripts, the PythonWin interactive window displayed<br><span style="font-family: courier new,monospace;">Registering COM server...</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">Registered: PythonDemos.Utilities </span><br>
<br>[VBA]<br><span style="font-family: courier new,monospace;">Sub TestPython()</span><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Set PythonUtils = CreateObject("PythonDemos.Utilities")</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">response = PythonUtils.SplitString("Hello from VB")</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">For Each Item In response</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> MsgBox Item</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">Next</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">End Sub</span><br>
<br>The code stopped at "<span style="font-family: courier new,monospace;">response = PythonUtils.SplitString("Hello from VB")</span>".<br clear="all"><span style="font-family: courier new,monospace;"></span><br>
-- <br>Love. Peace. Music.