Useful blocks for data entry – Nisus Writer Pro User Manual

Page 430

Advertising
background image

410

The Nisus Writer Pro Macro Language

Macros, the Deeper Workings

End

Just following the Begin Perl command of a Perl block (as illustrated above) you can specify Nisus
Writer Directives the same way as in Nisus Express Perl macros. Each Perl block can have its own
different such directives. These directives specify the!location from where to get the input and where
to put the output. For example:

#Nisus Macro Block
#source front selection
#destination front selection
#End Nisus Macro Block

The instruction above tells the Perl block to use the front window selection as the default
source (STDIN) and front selection as the destination (STDOUT).
Without any specifications, the default output (all simple print commands) go to a new
document window.
Variables that have been defined by your macro are automatically available as Perl scalars.
Note however that the reverse is not true. That is, variables defined in your Perl code are
strictly local to that Perl block and so are not available outside that block of Perl. However,
changes made inside the Perl block to the variables defined outside the Perl block are
reflected outside.
The following is an example which alters the contents of the current Clipboard, replacing by
'Nisus' all instances of the text you type into the dialog:

$name = Prompt Input 'What is your name?'
$contents = Read Clipboard
Begin Perl

$contents =~ s/$name/Nisus/g;

End
Write Clipboard $contents

The following illustrates how to use a Perl block to have the While loop continue until a particular
string value is obtained:

$continue = 1
While $continue

$response = Prompt "Hello World", "details", "Stop", "Continue"
Begin Perl

if ($response eq "Stop") ( $continue = 0; )

End

End

The above macro will loop until you click the “Second Button”

Useful blocks for data entry

The following accepts user input of a valid numeric value only and keeps asking for the right value
if the entry is not a correct decimal or whole number. It can be modified for any specified type of
entry value by changing the highlighted portions.

$not_done = 1

$principal = '$120,000.00'
$prompt = "Enter principal in dollars."

While $not_done

$principal = Prompt Input “Dollar Principal”, $prompt, “Done”,
“$principal”
Begin Perl

$principal =~s/[\$,]+//g;#remove commas and dollar signs
$not_done = 0 if (($principal =~/^\d*\.?\d*$/) and

($principal !~ /^\s*$/));#This checks if it is a decimal number and
it is not an empty string.

if ($not_done) # If the entry is correct $bool is zero,

which means false, so this is not executed.

()$prompt = 'Your entry is not a number. Please correct it.';

}

End

Advertising