Workspace for Script Applications
Many of the concepts presented in these notes are accompanied by examples that you can try. Depending on the example, you will need either a script application or a standard application to work within. Instructions are provided here for preparing a script application. These instructions assume that you have a typical VTScada installation, located on your hard drive at C:\VTScada. If not, adjust the file path as required.
To create a standard application for use with some examples, refer to Workspace for Expressions
- In the VTScada Application Manager, start the Add Application Wizard.
- Select the Advanced option and click Next.
- Ensure that Create New is selected and click Next.
- Name the application. (Script 1 is suggested.)
- Use the drop-down type selector to select Script Application, then click Next.
- Deselect the Start Application Now check box before clicking Finish.
For each example, you will need to edit code before running the application.
Check that the icon matches. If not, you missed step 5.
Your application will be created. Most examples will ask you to use a text editor to modify the file AppRoot.SRC, which can be found at C:\VTScada\Script1, assuming that Script 1 is the name that you gave this application.
The default window background color is black. Black is also the default color of text in several user-interface tools that you might display in that window. Therefore, you might want to change the window color to gray1. Do so by modifying the Window call as follows:
Setting the window color to gray
The 7 comes from the VTScada Color Palette, which dates from a time when only the most expensive graphics cards supported a full 256 colors. While you are likely to use "<alpha-RGB>" colors in most situations, the palette remains a useful tool.
When making changes to a script application, you must stop, recompile, and then restart the application each time to see the changes. In a standard VTScada application, you may or may not need to restart the application, but you will always need to import file changes. When a restart is necessary, you will be prompted.
Write Code
- Using a text editor, open the file AppRoot.SRC within the application folder. (C:\VTScada\Script1\AppRoot.SRC)
- Modify the code to add a ZText function at about line 38 - just within the declaration of the Main state.
Note that this is being added within the Main state of the Graphics submodule. More about submodules soon.
Main [ ZText(100, 100, "Hello World!", "<FF000000>", 0); ]
- Change the title from "User Application" to "Greeting Application".
Part of the exercise is to identify the line where this change is to be made.
- Use the Import File Changes in the VAM to recompile the application and then start it.
Take a minute to learn a bit about how VTScada displays text and graphics. Continuing in the same application, change the statement as follows.
- Delete the ZText statement and replace it with a ZBar statement as follows:
ZBar(100, 200, 150, 50, "<FF0000FF>" { Blue });
- Stop the application, "Import File Changes", then restart.
- Change the color of the bar to green.
- Draw a second rectangle so that the two together make a plus sign +.
(Hint: This is just a matter of changing the four coordinates. But you will have to refer to the documentation for ZBar to understand how those coordinates work.) - Remove the second rectangle and draw a ZBox that will create a red border around the first rectangle.
Key Points
- Script applications are especially useful when learning the VTScada script language. They give you a simple module structure, a window, and the rest is yours to create.
- While the code in AppRoot.SRC of a script application is minimal, it is also a complete example of how every module throughout VTScada is built.
- Changes to VTScada code must be imported and compiled.
- The documentation is your friend when using functions.