Preprocessor tips

<< Click to Display Table of Contents >>

Navigation:  Command Language > Preprocessor >

Preprocessor tips

Square brackets

If you want to use a square bracket that is not intended for the preprocessor you can precede it with a grave (`) character, so this is not a preprocessor command but a piece of text with 6 characters.

`[This`]

Data Set or cell references

Always enclose set references and cell references in square brackets. This avoids ambiguity and is easier to read. For example, to get the value from the data set:

[*set NewIndex=[dsMine.ThisOne]]

Always enclose file, worksheet and column names in quotes even if they do not contain spaces:

[*dbopen dfExcel=’MyFile.xls’]

[*dbloop dlThisRow = dfExcel;’Sheet1’;’Value’,’Name’]

[*dbopen dfAcc=’MyFile.bdb’]

[*dbloop dlRow = dfAcc;’Questions’]

Nested commands

You can include preprocessor substitutions and commands inside other commands.  They can be nested to any level.  Examples might be:

[*set [dsSelect.lpSelect]My[&lpAlpha] = 0]

[*set Value = [dsSet.#]+[dsSet.MyOne]]

[*data dsThisTime () CSV = [ThisCSV].CSV]

[*dbloop dlRow = dfFile;’[ThisSheet]’;’[FirstCol]’,’[SecondCol]’]

Text in PP code

Always enclose text within single quotes if you want to treat it as text.

When the text in an index is referred to, always use @ to make sure that the exact text is used. For example, to get the text from the index:

[*set NewIndex=’[@MyText]’]

When the text in a data set is referred to always enclose in quotes. For example, to get the text from the data set:

[*set NewIndex=’[dsMine.ThisOne]’]

IMPORTANT: if a substitution begins with a [ then it is assumed to contain a value so:

[*set ThatPlace=dsPlaces.lpThis]

[*set ThatPlace=’[dsPlaces.lpThis]’]

[*set ThatPlace=[dsPlaces.lpThis]]

The first and second commands can be used to set ThatPlace to the text from [dsPlaces.lpThis]. The third command will fail unless [dsPlaces.lpThis] contains a valid number.

IMPORTANT: the text "15." or "15.0" is a valid whole number, so:

[*set Mytext=’15.0’]

[MyText]

[@MyText]

The first substitution outputs "15" not "15.0".  The second output "15.0".

Lookup in spreadsheet

To use a spreadsheet as a lookup table use *DBFINDROW and *LAST, for example:

[*dbfindrow FoundRow = dfFile;’Sheet1’;’Response’=’NA’]

[*dbloop dlFoundRow = (FoundRow)dfFile;’Sheet1’]

[*last dlFoundRow]

[*set FoundText = dlFoundRow.’Text’]

[*dbend dlFoundRow]

Functions (%START)

The following shows how to use the %start functions which show the values when the run was started:

[*set yyyy=%startyear]

[*set mm=%startmonth]

[*set dd=%startday]

[*set hh=%starthour]

[*set mm=%startminute]

[*set ss=%startsecond]

 

date = [yyyy]/[0mm]/[0dd]

time = [0hh]:[0mm]:[0ss]

 

[*set path=%startsetuppath]

[*set file=%startsetupfile]

 

file = [path]\[file]