Edit

For Each...break...continue...End For

The For Each ... End For is used to loop through either (a) the elements in a comma-delimited text string, (b) lines in a newline-delimited table, (c) an integer series, or (d) the selected records found by a search expression from one of the MoneyWorks tables. The loop is traversed once for each item list, or each record found in the order of the specified sort, e.g. the following will step through each transaction entered today, in the ordered entered (SequenceNumber):

Every For Each part must be terminated by an End For part.

Identifier: A name by which to reference the fields of records of the nominated list. Thus to get the transaction date of the record in the above example, you would use “TRANS.TransDate”.

In: A comma-separated list of values, an integer series, or a MoneyWorks List (table) selected from the pop-up menu.

    For each COUNTRY in "NZ,USA,CAN"

Comma-separated: Loops with COUNTRY = “NZ”, “USA”, “CAN”

    For each NUM in 1...5

Integer series: Loops with NUM = 1, 2, 3, 4, 5

Note: For series involving variables, you will need to enter the loop parameters as a calculation, e.g. to step through each available period:

         PER ="1..."+PeriodToNum(CurrentPer)

Parsing of "..." for a range can be disabled by turning off the Parse "number...number" as a numeric range for the loop checkbox. You should do this if iterating over user-supplied data such as the contents of a file. Parsing for a numeric range will also not happen if the data is more than 30 bytes long, or contains non-numeric characters.

Note: When looping through Categories, Departments or Classifications, Account parts (e.g. Accounts of Type) within the loop are automatically filtered to show only accounts/ledgers that match the current for-loop value.

Where: A search expression, normally involving fields from the nominated list, relational find, or pre-calculated selection. If no search is specified, the highlighted records in the list will be used (or all records if the list has not been opened). Click the Edit button to open the Calculation window. Examples:

steps through every incomplete (unpaid) debtor invoice

the first For loop steps through every highlighted product; the second loop finds every detail line involving the product, then uses a relational find to locate every outstanding purchase order containing those lines.

Note: The special test string file:// (optionally followed by a platform specific file path) can be used to read and step through the records in a text file. If the file cannot be located, the standard File Open dialog will be displayed, allowing you to choose the file. For example

        file://Users/Accounts/Documents/SupplierX/priceList.txt

will (on a Mac) open the priceList.txt file if it exists, otherwise the file open dialog will be displayed. To access a text file hosted on a web site, specify the URL to the file (e.g. http://www.somewhere.co/somefile.txt)

Note: If you want your report to run on the server, do not use <highlighted>. Instead precalculate the selection in an invisible control.

List: When stepping through the records of a tab or newline delimited list, the list to use. This can be a calculated result (preceded by =).

Sorted by: The field from the modified list by which to sort the records. Using the And option to provide another level of sort.