HP 3000 Manuals

Introducing Variables to Scripts [ HP DeskManager Customization ] MPE/iX 5.0 Documentation


HP DeskManager Customization

Introducing Variables to Scripts 

The second method of making sure that the subject of the item we wish to
send is correct is by prompting the user to type in the subject and
saving this input for use later in the script.  To do this we need to
know how to use variables in scripts.

The directive and active function mechanism allows for the saving and
substitution of strings of text.  To save text in a variable we use the
&SAVE directive, and to access it, we use the <VAR> active function.  For
this script, we also need a way of asking the user for input.  This will
be the <PROMPT> active function.

For example, the following simple script:

     &SAVE string <PROMPT "Type a string: ">
     &PRINT You typed in: <VAR string>
     &EXIT

when executed would look like:

     Workarea > SCRIPT "Test"
     Type a string: this is a string
     You typed in: this is a string

     Workarea >

Prompting for Information 

There is an alternative to including information on the script command
line, you can prompt the user for information from within a script file.
Our example script could look like this:

     &SAVE itemref <PROMPT "Enter item to send:    ">
     &FORWARD itemok <REF <MAKEQUOTED <VAR itemref>>>
     &PRINT I don't think you have created the report yet
     &EXIT
     $itemok Come here if the item is OK
     SEND <MAKEQUOTED <VAR itemref>> to Mary Smith / ACCTS01
     ACKNOWLEDGE 4
     URGENT
     MAIL
     &EXIT

The <PROMPT> active function writes the text in quotes to the terminal,
waits for the response then uses the user's response as the result of its
function.

&SAVE may be used to save data in variables whose names can be up to 16
alphanumeric characters starting with a letter.  So, in this case,
whatever the result of the <PROMPT> function is, will be saved in a
variable called "itemref".

The <VAR> active function specifies that itemref is a variable and allows
its contents to be used in the script.

Arithmetic operations 

Say we have to work out a sum in a script, for example:
2 multiplied by 3, plus 5 ( 2 * 3 + 5 ).  We'll need to use the <ADD> and
<MULTIPLY> active functions.

     &PRINT <ADD  <MULTIPLY  2 3>  5>

The way that HP Desk interprets this command line is:

     &PRINT <ADD <MULTIPLY 2 3> 5>

is first evaluated to

     &PRINT <ADD 6 5>

as 2 * 3 equals 6, then

     &PRINT 11

Which results in "11" being displayed on terminal.

Creating Loops 

Using variables we can also begin to create loops, as we mentioned
earlier, by using simple counting:

     &SAVE count 1
     &PRINT this is the beginning
     $START
     &PRINT the count is <VAR count>
     &SAVE count <ADD <VAR count> 1>
     &BACK start <LESS <VAR count> 10>
     &PRINT this is the end
     &EXIT

Using System Variables and Comments 

Suppose you want to write a script which will print a system
variable--for example, today's date--to the screen.

You also want to add comments to the script so that people reading it
know what it is doing:

     &COMMENT This script displays today's
     &COMMENT date on the screen.
     &COMMENT
     &PRINT <QUOTE Today is <DATE>>
     &COMMENT Note that QUOTE and DATE are active
     &COMMENT functions, note the angled brackets

The &Print statement is evaluated by HP Desk in the following way:

     &PRINT <QUOTE Today is <DATE>>

which becomes:

     &PRINT <QUOTE Today is 11/11/91>

which becomes:

     &PRINT "Today is 11/11/91"

which is then displayed on the screen as:

     "Today is 11/11/91"

Using Local Variables 

A local variable can be defined to be used as a variable that is only
used within the current script file.  The command to define a variable of
this type is &LOCALVAR. This can be useful if you use one script file to
call another, and both script files have variables with common names.



MPE/iX 5.0 Documentation