Jul-26-2018, 08:05 PM
Hello guys,
I have a simple challenge for you.
I'm the author of a tool called Virtual Forms. It is an ActiveX server control.
For now, we have only used it from VBA, VB.NET & C#
Now my colleagues asked me if we could use it from Python on windows.
It works, but, because I'm also not a Python expert I got stuck on one line of code.
Here is the code that works:
The control accepts the VFFile, DatabaseType and the ConnectionString parameter, because when we run the line with code:
![[Image: VirtualForm2_2018-07-26_16-14-49.png]](https://www.virtual-forms.com/sharing/VirtualForm2_2018-07-26_16-14-49.png)
Then, for example, in VBA I use this line of code to change the text that is in a textbox:
![[Image: VirtualForm2_2018-07-26_16-30-00.png]](https://www.virtual-forms.com/sharing/VirtualForm2_2018-07-26_16-30-00.png)
But when I try it from Python I got this error:
If you want to try it out you will need to install the setup for this Virtual Forms control that is in this download:
https://www.virtual-forms.com/sharing/Vi...0.0.31.zip
And here is the VFFile:
https://www.virtual-forms.com/sharing/VFFilePython.vf
Any suggestion is welcome.
Thanks,
Davor
I have a simple challenge for you.
I'm the author of a tool called Virtual Forms. It is an ActiveX server control.
For now, we have only used it from VBA, VB.NET & C#
Now my colleagues asked me if we could use it from Python on windows.
It works, but, because I'm also not a Python expert I got stuck on one line of code.
Here is the code that works:
import win32com.client as win32 vf1 = win32.gencache.EnsureDispatch('VirtualForm2.VirtualForm') vf1.VFFile = r"C:\Users\WinPIS\Desktop\VFPython\VFFilePython.vf" vf1.DatabaseType = 2 vf1.ConnectionString = r"DRIVER={MySQL ODBC 5.3 Unicode Driver};" \ "Port=3306;" \ "SERVER=myserver;" \ "DATABASE=mydb;" \ "USER=myusr;" \ "PASSWORD=mypass;" \ "OPTION=3;" #vf1.OpenVirtualFormDesigner() vf1.ShowVirtualForm("VF2")As we can see, we can call methods and pass some parameters to this control.
The control accepts the VFFile, DatabaseType and the ConnectionString parameter, because when we run the line with code:
vf1.ShowVirtualForm("VF2")it opens the Virtual Form, connect to the MySQL database and displays the data. Here is the screenshot:
![[Image: VirtualForm2_2018-07-26_16-14-49.png]](https://www.virtual-forms.com/sharing/VirtualForm2_2018-07-26_16-14-49.png)
Then, for example, in VBA I use this line of code to change the text that is in a textbox:
vf1.TextBox("VF2", "[customerid]").Text = "888"And here is the screenshot that it works in VBA:
![[Image: VirtualForm2_2018-07-26_16-30-00.png]](https://www.virtual-forms.com/sharing/VirtualForm2_2018-07-26_16-30-00.png)
But when I try it from Python I got this error:
Error:Traceback (most recent call last):
File "C:/Users/WinPIS/PycharmProjects/VFPython/VFPythonFile.py", line 20, in <module>
vf1.TextBox("VF2", "[customerid]").Text = "888"
AttributeError: 'tuple' object has no attribute 'Text'
This only works in windows.If you want to try it out you will need to install the setup for this Virtual Forms control that is in this download:
https://www.virtual-forms.com/sharing/Vi...0.0.31.zip
And here is the VFFile:
https://www.virtual-forms.com/sharing/VFFilePython.vf
Any suggestion is welcome.
Thanks,
Davor