| Applying science to business management |
  
Using Libraries
If you have a set of functions that you want to use in more
than one script, you should save the functions in a separate
library file. A library file is simply a standard script file
(.dsb) that you load into another script when it is first opened.
For example, assume you want to modify the example Decision
Tree.dsb so that it displays a progress bar on each page.
That is, change a typical page from this
to this
Decision tree scripts use the primitive choose
to display options to the user. You can insert a progress bar on
each page by redefining choose
in a library file and including this file in the original
decision tree script.
First you must open a blank script and enter a new definition
for choose.
choose(query:=dialogtemplate):=
@choose(ProgressBar+query)
The first argument passed to choose
is the text that will be displayed (query). Normally you
do not supply any arguments with choose.
Instead, the display text is found in the Form Window. You
accomplish this by making the first argument optional with a
default value of dialogtemplate.
All the new definition of choose
does is precede the usual query with a progress bar and then call
the primitive version of choose.
You call primitives explicitly using the @ operator.
The definition for ProgressBar is as follows:
ProgressBar():={
var pct=user(floor(StepsDone++/TotalSteps*100));
"<div align=\"right\">
<table border=\"1\" cellpadding=\"0\
cellspacing=\"1\" width=\"100\">
<tr><td width=\""+(pct+1)+"\"
bgcolor=\"#0000FF\">
<font
size=\"1\"> </font></td><td></td></tr>
</table>"+pct+"% Done</div>";
}
This definition calculates the percent done from two variables
(StepsDone and TotalSteps) and generates a small
HTML table that looks like a progress bar.
Once you have entered a definition for choose and ProgressBar,
save the file using the name choose.dsb (any name will
do).
To use the new definition of choose in the original
decision tree script, open the script and click Tools, Script
Options, Include library files.
This opens a dialog box where you list all library files you
want to include in your script.
Finally, you must modify the script slightly because the new choose
function expects there to be definitions for StepsDone and
TotalSteps in your script. Change the root definition from
Root:=branch(choose,Ins1,Ins2)
to
Root:=(
var TotalSteps=4,StepsDone=0;
branch(choose,Ins1,Ins2);
)
Now you are done. You will notice that the decision tree
script does not look any different except for the change to Root.
The new choose function is used just like the original
primitive. Also, if you decide to change the way progress bars
are displayed, all you need to change is the file choose.dsb.
Every script that uses this library file will change
automatically.
Library files can be placed in either the program directory or
the script directory. If you place a library file in the
directory where the server is located (usually C:\Program
Files\Vanguard\Dscript Server 4\Decision) then the library file
is available to all scripts. If you place the library file in the
directory where the script is located, then only scripts in that
directory can access the library file.
|