# Blocks

Blocks group functionality that otherwise does not necessarily relate to a single, individual row. There are six blocks: comments, macros, constants, validations, settings and lists.## Comments

Comments include information meant for the template developer but not visible to the user. Generally comments are used to document your template so you can remember later what you did. Comments can be added anywhere within the template.Comments start with /* and end with */ (the same as C block comments). Everything between these two marks is stripped out before displaying the template. Examples include:

/* This is a comment here */

/*

and here is another one

*/

"Label" "" /* this is legal, too */ var ::

## Macros

Macros make writing templates easier by grouping repetitive numbers and formulas in one place and then being able to use those macros throughout the template.Macro definitions begin with [macros_begin] and end with [macros_end] (including the brackets), with each of these on their own line. Between the block begin and block end statements, however, spaces and returns are ignored. There can be multiple macros per template. Each macro is defined as:

An example:

[macros_begin]

xx:1+2 ::

yy:42 ::

[macros_end]

A "" a ::

Result "" res:a*xx/yy

When res is calculated the formulas and variables defined for xx and yy are surrounded by parentheses and then substituted into the formula, like so:

a*(1+2)/(42)

Another example is to define a formula that gets used repetitively throughout the template:

[macros_begin]

xx:a+b ::

[macros_end]

A "" a ::

B "" b ::

"Result^2" "" res2:xx^2 ::

"Result^3" "" res3:xx^3 ::

This would leave the formula for res2 as (a+b)^2 and res3 as (a+b)^3.

It is important to note that macros substitute on a first found, first replaced basis. You can cascade macros using this rule:

[macros_begin]

xx:a+b ::

b:5

[macros_end]

A "" a ::

"Result^2" "" res:xx^2 ::

This would first substitute (a+b) for xx and then substitute (5) for b, which would yield the following expression for res:

(a+(5))^2

## Constants

Introduced in powerOne v3, constants make writing templates easier by grouping numbers or tables in one place and then being able to use those constants throughout the template. Constants are similar to macros but a result is derived first and then that result, through its variable name, will be used elsewhere in the template.Constant definitions begin with [constants_begin] and end with [constants_end] (including the brackets), with each of these on their own line. Between the block begin and block end statements, however, spaces and returns are ignored. There can be multiple constants per template. Each constant is defined as:

An example:

[constants_begin]

xx:25 ::

yy:37 ::

[constants_end]

A "" a ::

Result "" res:a*xx/yy

Constants are particularly useful for look-up tables that are used multiple times. This example looks up the entered row and column, returning the appropriate result:

[constants_begin]

t1:[[3;4;5;6];[7;8;9;10];[11;12;13;14];[15;16;17;18]] ::

[constants_end]

"Row 1-4" "1" row ::

"Column 1-4" "1" col ::

Result "" res:getItem(t1; row; col)

In reality, macros create a hidden row at the bottom of the template that can referenced by other rows. This means that equations can be used as well as numbers or tables. Setting a constant to 1/3 will use the resulting 0.3333 to full precision.

## Validations

Validations test user entered data. These tests are done BEFORE any calculations are begun and all tests are done at the same time with all error messages collected and displayed to the user. If any errors are found, the calculation stops.Validation definitions begin with [validations_begin] and end with [validations_end] (including the brackets), with each of these on their own line. Between the block begin and block end statements, however, spaces and returns are ignored. There can be multiple validations per template. Each validation is defined as:

The error message is always in quotation marks and the no error returns an empty string (two quotation marks with no space between them). Examples (all from the Time Value of Money template):

[validations_begin]

if(pyr < 0; "Periods/Yr must be > 0"; "") ::

if(cyr<=0;"Compounds/Yr must be > 0";"") ::

if(end

if(begin<=0;"Begin Period must be > 0";"")

[validations_end]

## Settings

Settings are used to define application preferences not available to the user. There are four application settings: hasGlobals, calendar modes, trig modes and onEnter. The first three are defined here. onEnter is defined in the Circular References & Conversions section.Setting definitions begin with [settings_begin] and end with [settings_end] (including the brackets), with each of these on their own line. Between the block begin and block end statements, however, spaces and returns are ignored. The settings block would look like this:

[settings_begin]

hasGlobals ::

degrees ::

calActual ::

useUnits ::

[settings_end]

hasGlobals: Tells the template to use the automatically updated currency data. See the Using Currencies section for more details.

Trig Modes: either set all trig computations to use degrees or radians.

Calendar Modes: use either actual day-count method (calActual), 30/360 day-count method (cal30360), actual/360 day-count method (calActual360), or actual/365 day-count method (calActual365).

- Actual: actual days between dates, including leap days.

- 30/360: 360 days per year plus 30 days per month for the remainder.

- Actual/360: 360 days per year plus actual count for remainder.

- Actual/365: 365 days per year plus actual count for remainder.

useUnits: when performing mathematics with feet and inches, powerOne automatically strips the units. Lengths, areas and volumes are all treated as their equivalent inches. This setting tells the template to use the units as entered instead.

## Material List

Available only in the Library, powerOne includes a special template called Materials List. This template acts as a check list. Templates can directly interact with the Materials List. Many of the Construction templates, for instance, includes the ability to select the Send button then choose to send results to the Materials List. If the Materials List is not downloaded to powerOne then this functionality is hidden.List definitions begin with [list_begin] and end with [list_end] (including the brackets), with each of these on their own line. Between the block begin and block end statements, however, spaces are ignored. Each list item is a standard text string. A replacement indicator can be used to insert calculated data:

"%v lbs chalk", pounds

"%v- %v bags, concrete", bags, size

%v tells powerOne to use the results of the variable in its place. The first %v uses the first variable, the second one uses the second variable, etc. Note that text for the list is always in quotes and separated from the variables by a comma. Variables are also separated by commas. Finally note that, unlike other blocks, double-colon (::) is not used to separate list items. Instead, put one list item per line.

An example (from Fence Estimator template):

[list_begin]

"%v fence posts",posts

"%v- %v rails",railbds,pd

"%v pickets",pickets

"%v fasteners",fast

"%v nails",nails

"%v screws",screws

[list_end]