Advanced macro notes, Included macros – Nisus Writer Pro User Manual

Page 431

Advertising
background image

Customizing & Automating Solutions

411

End

The above macro block is used in the “Mortgage Payment Calculation” macro supplied.

The following is the same block but adjusted to accept only alphabetic character strings with other
conditions. Compared to the previous one, the first highlighted line is removed. The second
highlighted line is simplified to check for alphabetic characters and white space characters.

$not_done = 1

$name = 'Your Name'
$prompt = "Enter your name please."

While $not_done

$name = Prompt Input “Your Name”, $prompt, “Done”, “$name”
Begin Perl

$not_done = 0 if (($name =~/^[a-z ]+$/i) and ($name ne 'Your

Name') and (length($name)

>

1));#This checks if it is alphabetic and

not the default text and more than one character long.

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

zero, which means false, so this is not executed.

()$prompt = 'Your entry must only be alphabetic. Please correct it.';

}

End

End

Advanced macro notes

There is only one Menu Command looping construct at present. It is however very functional
allowing you to nest within it, any number of Perl blocks and Menu Command blocks.
Presently there are no calculation possibilities within a Menu Command block. Therefore all
calculations require a Perl block.
If you want to create a Menu command loop that never terminates until you use Command . to force
it to stop, begin the loop with:

While 1

All text attributes are removed from string variables (e.g.: $message = "Hello World") if any Perl
block changes the value of that variable during its execution. So when attributes are imported to
preserve, make sure the variable is not altered by any intervening Perl blocks before being inserted
into a document.
Remember that the Insert Text command uses the attributes of the selection to insert the text and
the Insert Attributed Text command inserts a string using the text attributes of the inserted text.

Included macros

The following macros are included with the application. More will be added in the future and you
should check our web site periodically for additional macros.
<http://www.nisus.com/pro/macros/>

Calculation

Average Column

This macro evaluates the average of the column of numbers,
starting at the current cell and placing the results in the last cell of
the column. Note: empty cells are not counted so they do not affect
the average, but cells with a zero in them are counted and they do
affect the average.
Be sure to have an empty cell in the column otherwise the last cell
will be overwritten with the result. Its contents will not be summed.
Place the insertion point in the first cell of the column to be
averaged.

Average Row

This macro evaluates the average of the row of numbers, starting at
the current cell and placing the results in the last cell of the row.
Note: empty cells are not counted so they do not affect the average,
but cells with a zero in them are counted and they do affect the
average.
Be sure to have an empty cell in the row otherwise the last cell will
be overwritten with the result and its contents will not be summed.
Place the insertion point in the first cell of the row to be averaged.

Advertising