Results 1 to 4 of 4

Thread: Using Python with Vb6

Hybrid View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    95

    Using Python with Vb6

    well i've searched for two days on how to fix this problem and found nothing. what i'm trying to do is call python functions and stuff from within vb6. Here's the steps I took

    1) I have vb6 and sp6 installed
    2) I install activepython 2.7 because it includes win COM stuff
    3)I create the folder C:\PythonVB
    4)I created the python script called 'PythonVB3.py' with the following code

    Code:
    class PythonVB3:
        #Public Methods available to VB    
        _public_methods_ = ['SayHello']
        #Class Name Created in VB.
        #Example Set objPython = CreateObject("PythonVB3.Demo")
        _reg_progid_ = "PythonVB3.Demo"
        #Never Copy this GUID!  Use pythoncom module to create a new one
        #Example: import pythoncom
        #         print pythoncom.CreateGuid() 
        _reg_clsid_ = "{EE2946AE-79DD-49D1-992D-F4FF6431A2F0}"
    
        def SayHello(self):
            return "Hello from Python!!"
    
    if __name__ =='__main__':
        print "Registering COM Server..."
        import win32com.server.register
        win32com.server.register.UseCommandLine(PythonVB3)
    5) I double clicked the script above which registered itself
    This tool 'RegDLLView' from nirsoft shows it registered correctly



    6)I created a new standard exe project in vb6 with the following code
    Code:
    Private Sub Form_Load()
    Dim objPythonVB As Object
    Dim retval As Long
    Set objPythonVB = CreateObject("PythonVB3.Demo")
    retval = objPythonVB.SayHello()
    MsgBox retval
    End Sub
    7)when I compiled and try to execute(in C:\PythonVB) I get error


    I tried manually adding a reference to pythoncom27.dll too and it wouldn't let me :\ any help or advice would be much appreciated. I also uninstalled/reinstalled everything and only have 1 version of python installed.

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Dec 2010
    Posts
    95

    Re: Using Python with Vb6

    ok I got it to work, i'll leave it unanswered for a day to let people guess if they want. i'll give you a hint though, there's nothing wrong with the code short of retval being declared a long when it should be a string. That's not the main issue though.

  3. #3
    Addicted Member
    Join Date
    Aug 2013
    Posts
    236

    Re: Using Python with Vb6

    Quote Originally Posted by Vbstr View Post
    ok I got it to work, i'll leave it unanswered...
    Vbstr's last theorem

  4. #4
    New Member
    Join Date
    Oct 2017
    Posts
    1

    Re: Using Python with Vb6

    Sir,
    how did you manage to work through this? I would be highly interested in learning the solution as I'm facing similar issues.

    Bart

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width