The Scripts Tutorial
ViewPoint supports script files, which can be used by external
applications to call functions directly.
The script file is just a plain text file with a special file type
or extension.
The script commands are the same as those used in normal ViewPoint
scripts (i.e. those attached to buttons or in the global scripts
(File/Edit Scripts on the menu)), plus the following command is
used to 'associate' the script with a ViewPoint database:
- SetCurrentDB "myfile/vpf"
Note that this is a compile-time command which tells the script
compiler to look in the global scripts of that particular database
file for any function or procedure calls. So, if you have a user-defined
function in the global scripts for that file, you can call it within
the script provided you've put the SetCurrentDB command in
first. The filename can be relative to the location of the script
file itself, or it can be an absolute path in 'native' format, if
you want.
Another new command is used by the script to open and bring to
the front a particular database file:
- SetCurrentWin("myfile/vpf")
This command is actually quite different from SetCurrentDB,
even though it looks similar! SetCurrentWin loads the given
file (if it isn't already loaded), and brings the window to the
front. Any script that wants to make things happen in the 'front-end'
(i.e. user interface) side of ViewPoint will need to issue this
command to get the relevant database loaded and made current.
Note: SetCurrentDB doesn't take brackets, while SetCurrentWin
insists on them. Think of the difference as indicating that the
argument to SetCurrentDB is a literal string (compile-time), while
the argument to SetCurrentWin is an expression (run-time).
After issuing this command, CurrentDB, CurrentRecset
e.t.c. will point to this file, and you can use commands like Layout()
to move to a different layout.
As an example, a script that opens a customer address file, goes
to the customer details layout and then displays the record for
a given customer might look like this:
SetCurrentDB "Cust/vpf"
SetCurrentWin("Cust/vpf")
Layout("Customer Details")
CurrentRecset.Seek("Eric Smith")
The idea is that the external program that wants to show this database
record would create the script file itself with the required customer
name in it, then run the script using ShellExecute.
Note: that the Seek() command can take multiple arguments:
the argument list is used to perform an indexed search on the relevant
query or table to locate the required record, so the number of arguments
depends on what sort order has been given to the layout.
The sort order can be set either by setting the clustering key
of the table, or by generating a new query with the required sort
order (to do this, perform the sort while in Layout view - this
will create a new query as a sorted version of the original table).
|