It is often required to export recorded Visionic macros to the VBScript. This option can be useful in variety of situations. For example:
- Allow your macros to be started from another process as command-line processes
- Allows you to customize operations in the macros using VBScript language
- Allows your macros to be started from a scheduled job (cron job) to periodically perform operations.
The export function is not a part of Visionic5, mostly because of the changing nature of the macro language as we know it. In the last days of Visionic4, the language has been rapidly expanded to include new instructions, such as looping through record set and similar. These new features blocked the existing Export to VBScript functionality.
In this blog, you can download vbscript-files-that-will-export-visionic5-macros-from-the-project-into-the-vbscript-language.zip. The process is very simple and can be done in the following way:
Unzip all files into the single directory and then from the command prompt execute this command:
cscript.exe export_macro.vbs //nologo <full path to compiled MDB file> <macro name> >macro.vbs
In the command line above, replace the following:
|<full path to compiled MDB file>||C:\Users\John\Documents\Visionic Projects\Demo1\ini_files\database\demo1.mdb|
|<macro name>||Name of existing / already recorded macro. If macro name has space(s) in the name, surround it with quotes.|
Once the script is exported, open the generated VBS file in a file editor. As you can see the macro is embedded in the sub called RunMacro. At the top of the code there is initialization routine for the parameters; you can change this instruction to provide macro parameters from command line or similar.
The macro can be run with the command:
The constants on the top of the resulting VBS file dictate the IP address of the server (whether the server is on local machine or not).
Once exported, the macro can be manually updated as necessary. Feel free to change macros code and experiment with the VisApp object (source of which is at the end of the file).