A script is a simple computer program which uses Microsoft's Windows Script technology. Scripts are text files written in one of the many different script languages that support Windows Script, such as VBScript, JScript (JavaScript), Perl, Python, Ruby and PHP. VBScript and JScript come with Windows and are always available, whereas other scripting languages must be installed by you on your computer before you can use them. (See below for links to free versions of these scripting languages.) Because scripts are text files, they are easy to create and modify.
Scripts can be used with WEAP in two different ways:
Internally: to create more powerful expressions and functions for a WEAP model (e.g., create a script to calculate reservoir water quality, and Call the script from a WEAP expression).
Externally: to automate WEAP via its Application Programming Interface (API) to perform a sequence of actions (e.g., create and run 100 WEAP scenarios by varying the value of several parameters (sensitivity analysis), and export the results to Excel for further analysis);
WEAP has its own built-in script editor that can be used to edit, interactively debug and run scripts. You may also use any text editor to create or edit your scripts.
When used internally, scripts can either be called from the Call function in an expression, or associated with events that will run at various times before, during and after WEAP's calculations. When Called by an expression, functions take only numeric parameters and should always return a numeric value (integer or floating point). Functions can have any number of parameters (or none at all), but it is the user's responsibility to pass the correct number of parameters in a comma separated list in the Call statement. For example, Call(Test.vbs ! Add, 4, 5) or Call(Test.js ! add, 4, 5)
You may also run a script from the main menu: Advanced, Scripting, Run.
A few trivial example functions are shown here.
VBScript:
Function Add(x, y)
Add = x + y
End Function
Function Multiply(x, y)
Multiply = x * y
End Function
JScript:
function add(x, y)
{
return x + y;
}
function
multiply(x, y)
{
return x * y;
}
Python:
def add(x, y):
return x + y
def multiply(x, y):
return x * y
In VBScript, each function starts with the keyword Function and ends with the keywords End Function; function results are set by assigning values to the function name (in this case Add or Multiply). In JScript and Python, function results are set with the return keyword.
Some other internet-based resources you may find useful:
Windows
Script Information
VBScript tutorial
VBScript reference guide
JScript reference guide
Free versions of Python, Perl,
PHP and Ruby