473,413 Members | 1,989 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

python win32com dispatch.withevents

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
Expand|Select|Wrap|Line Numbers
  1. Option Explicit
  2.  
  3. Public Event Onvb2py(ByVal val As Variant)
  4. Public Event Onpy2vb(ByVal val As Variant)
  5. Public Event OnClose(ByVal idx As Integer)
  6.  
  7. Private Sub cmdClose_Click()
  8.       Unload Me
  9.       RaiseEvent OnClose(0)
  10. End Sub
  11.  
  12. Private Sub cmdPY2VB_Click()
  13.       Text1.Text = pyvalue
  14.       RaiseEvent Onpy2vb(pyvalue)
  15. End Sub
  16.  
  17. Private Sub cmdVB2PY_Click()
  18.       RaiseEvent Onvb2py(Text1.Text)
  19. End Sub
  20. --------------------------------------------------------------------------------
  21.  
  22. VB6.0 Class Code
  23.  
  24. Option Explicit
  25.  
  26. Private WithEvents fm As Form1
  27.  
  28. Event Onvb2py(ByVal val As Variant)
  29. Event Onpy2vb(ByVal val As Variant)
  30. Event OnClose(ByVal idx As Integer)
  31.  
  32. Private mpy As Variant
  33.  
  34. Public Sub Show()
  35.       fm.Show
  36. End Sub
  37.  
  38. Public Sub SetPyValue(ByVal val As Variant)
  39.       mpy = val
  40. End Sub
  41.  
  42. Private Sub Class_Initialize()
  43.       Set fm = New Form1
  44. End Sub
  45.  
  46. Private Sub Class_Terminate()
  47.       If Not fm Is Nothing Then
  48.             Set fm = Nothing
  49.       End If
  50. End Sub
  51.  
  52. Private Sub fm_OnClose(ByVal idx As Integer)
  53.       Unload fm
  54.       RaiseEvent OnClose(idx)
  55. End Sub
  56.  
  57. Private Sub fm_Onpy2vb(ByVal val As Variant)
  58.  
  59.       RaiseEvent Onpy2vb(val)
  60.       fm.Text1 = mpy
  61. End Sub
  62.  
  63. Private Sub fm_Onvb2py(ByVal val As Variant)
  64.       RaiseEvent Onvb2py(val)
  65. End Sub
  66. --------------------------------------------------------------------------------
  67.  
  68. Call Python Code
  69. import win32com.client
  70.  
  71. vbcom = win32com.client.Dispatch("nVBCOM.clsConn")
  72. vbevent = win32com.client.WithEvents(vbcom,VBEventHandler)
  73.  
  74. class VBEventHandler:
  75.     def Onpy2vb(self,val):
  76.         val = "python...value"
  77.         vbcom.SetPyValue(val)
  78.  
  79.     def Onvb2py(self,val):
  80.         print "vbvalue 2 python : " + val
  81.  
  82.     def OnClose(self,val):
  83.         print "Close"
  84.  
  85. def run():
  86.     try:
  87.         vbcom.SetPyValue("Intial py value")
  88.         vbcom.Show()
  89.     except:
  90.         print "Error"
  91.  
  92. if __name__ == "__main__":
  93.     run()
Jan 16 '14 #1
0 1585

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Florian Fredegar Haftmann | last post by:
Hi! I'm working on a tool which helps in testing applications with web-frontends (on Windows) On thing I would like to test ist the occurence of JavaScript errors; the idea is that the test...
1
by: Patrick | last post by:
I am investigating a web-based app wherein I wanted to provide html form frontends to an Excel spreadsheet sitting on a MS Windows server; with each authenticated HTTP user having thier own...
1
by: Chris Curvey | last post by:
if I'm using Dispatch() to manage a COM object (IE), is there a way to get ahold of the process handle so that I can bump it's priority?
0
by: kenchanningphd | last post by:
Can someone post or point me to a fairly simple example where a COM interface (other than the standard ones already exposed by the win32com library) is implemented in python. I fear I am doing it...
1
by: g.franzkowiak | last post by:
I'm trying to use a proprietary windows software with COM and win32com. The result is everytime the error message com_error: (-2147418113, 'Catastrophic failure', None, None) I've read this in...
0
by: todddeluca | last post by:
I am posting code for calling almost any python function from php, because it seems generally useful. Please feel free to suggest improvements or tell me this has already been done better...
0
by: vml | last post by:
I am a newbie in python and com. I am trying to use python and com to access to a software. I had a look in the file .py describing the interface (generated by makepy) and I found some dispatch...
3
by: Ray | last post by:
Hi, I'm working on something with mysql and excel. I'm using python and win32com. All major function works, But I have two problems: 1. the output need to do "auto fit" to make it readable. ...
3
by: vml | last post by:
Hello, I am really new in python scipy win32com and scipy I tried to setup a COM server to interact with vb 6 the pythom COM server is : from win32com.server import exception, register import...
2
by: Ray | last post by:
Hi, I need to use cell's background color. when I record a macro from excel, it shows: Rows("7:7").Select With Selection.Interior .ColorIndex = 8 .Pattern = xlSolid
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.