1.Declare, the vbcom was Global variable
2.After, vbcom was closed(use vb close button) but, the vbcom process is activating , Certainly!
3.Then, declare the vbcom was local variable but, a function(py2vb button) is not operating...
4.ASK!!!
•When the vbcom is local variable
•How do I write the code to operate the py2vb button
[ActiveX EXE]
VB6.0 Form Code
2.After, vbcom was closed(use vb close button) but, the vbcom process is activating , Certainly!
3.Then, declare the vbcom was local variable but, a function(py2vb button) is not operating...
4.ASK!!!
•When the vbcom is local variable
•How do I write the code to operate the py2vb button
[ActiveX EXE]
VB6.0 Form Code
Code:
Option Explicit
Public Event Onvb2py(ByVal val As Variant)
Public Event Onpy2vb(ByVal val As Variant)
Public Event OnClose(ByVal idx As Integer)
Private Sub cmdClose_Click()
Unload Me
RaiseEvent OnClose(0)
End Sub
Private Sub cmdPY2VB_Click()
Text1.Text = pyvalue
RaiseEvent Onpy2vb(pyvalue)
End Sub
Private Sub cmdVB2PY_Click()
RaiseEvent Onvb2py(Text1.Text)
End Sub
--------------------------------------------------------------------------------
VB6.0 Class Code
Option Explicit
Private WithEvents fm As Form1
Event Onvb2py(ByVal val As Variant)
Event Onpy2vb(ByVal val As Variant)
Event OnClose(ByVal idx As Integer)
Private mpy As Variant
Public Sub Show()
fm.Show
End Sub
Public Sub SetPyValue(ByVal val As Variant)
mpy = val
End Sub
Private Sub Class_Initialize()
Set fm = New Form1
End Sub
Private Sub Class_Terminate()
If Not fm Is Nothing Then
Set fm = Nothing
End If
End Sub
Private Sub fm_OnClose(ByVal idx As Integer)
Unload fm
RaiseEvent OnClose(idx)
End Sub
Private Sub fm_Onpy2vb(ByVal val As Variant)
RaiseEvent Onpy2vb(val)
fm.Text1 = mpy
End Sub
Private Sub fm_Onvb2py(ByVal val As Variant)
RaiseEvent Onvb2py(val)
End Sub
--------------------------------------------------------------------------------
Call Python Code
import win32com.client
vbcom = win32com.client.Dispatch("nVBCOM.clsConn")
vbevent = win32com.client.WithEvents(vbcom,VBEventHandler)
class VBEventHandler:
def Onpy2vb(self,val):
val = "python...value"
vbcom.SetPyValue(val)
def Onvb2py(self,val):
print "vbvalue 2 python : " + val
def OnClose(self,val):
print "Close"
def run():
try:
vbcom.SetPyValue("Intial py value")
vbcom.Show()
except:
print "Error"
if __name__ == "__main__":
run()