How to Embed VBS in Python
Embedding Visual Basic Studio code into your Python scripts can be a useful procedure to know if you have previously coded similar applications in VBS and do not wish to recode them in Python. Python is a flexible scripting language used primarily in Web application development and can interact with other kinds of software engineering platforms, such as Visual Basic.
Instructions
-
-
1
Initiate an instance of a Python script by beginning the coding with the following lines of code:
#include <Python.h>
int main(int argc, char *argv[])
{
PyObject *pName, *pModule, *pDict, *pDunc, *pvalue;
if (argc <3)
{
printf("Usage: exe_name python_source function_name\n");
return 1;
}
-
2
Create a class to recognize the VBS code in Python by using the following code snippet as a guide and modifying it to fit your needs:
pClass = PyDict_GetItemString(pDict, argv[2]);
if (PyCallable_Check(pClass))
{
pInstance = PyObject_CallObject(pClass, NULL);
}
-
-
3
Embed the VBS code by calling the class that you created in the previous step and then inserting the VBS code. For example:
class Multiply:
def __init__(self):
self.a = 6
self.b = 5
def multiple(self):
c = self.a*self.b
print 'This is the result', self.a, 'x', self.b, ':', c
return c
-
1