export
PATH
,
FORMULA
,
SEPARATOR
,
ENCODING

The export statement exports the selected rows in the current database into a text file.


Parameters

This statement has four parameters:

path – is a path to the file to be saved, including the file name (see Files and Folders for more information about file paths).

formula – is the formula that will be used to extract data from the database and build the exported text. If the formula results in empty text (“”) for a record then that record will not be exported. The formula usually references fields in the database being scanned. If may also use the seq( function to include the number of each record (within the scan).

To export line items add a Ω (Option-Z) after the line item field names in the formula. Each line item will be output on a separate line. Warning: All the line item fields must have the same number of fields, for example Qty1…Qty6, Price1…Price6, etc. If some line items have more or less fields, the export will not work correctly. Remember, any field name that ends with a number will be treated as a line item, so if your invoice database contains fields named Address1 and Address2 you will not be able to export the line items using this method.

separator – is the separator character that will be inserted in between records in the output text. This parameter is optional, if it is omitted, then no separator will be inserted (you can also include it in the formula itself, though this will result in an extra separator being added at the end of the exported text file).

encoding – name or numeric value of the encoding scheme used to store the text as binary data. Common encodings include:

ASCII (7 bit)
UTF-8 (Unicode)
MacOSRoman (used by OS 9)

The encoding parameter is optional. If it is omitted, UTF-8 encoding will be used. If the encoding value is preceded by the word lossy (for example "lossy MacOSRoman") then lossy conversion is allowed (see below for more information about lossy conversion).

Note: Spaces and punctuation in this parameter are ignored, and names may be in either upper or loser case. For example "Mac OS Roman", "MACOSROMAN" and "Macos Roman" will all work for specify Mac OS Roman encoding. You can also specify the encoding numerically, for example 30 for Mac OS Roman. See the texttobinary( function for a full list of encoding names and numeric values.


Description

This statement exports data by scanning the current database and processing each record with a formula (similar to arraybuild, but builds a text file instead of an array). The result of the formula is placed into a text file. By changing the formula you can control what data is exported, and the arrangement of the data in the exported text.

This example exports the contents of a Contact database into a text file containing names and phone numbers.

export "~/Documents/Phone Book.txt",Last+", "+First+" - "+Phone,lf()

Here is a more complete example that prompts the user for a location to save the text file, then exports mailing list data.

local fileChoice
savedialog fileChoice,".txt"
if info("dialogtrigger") contains "cancel" rtn endif
export fileChoice,First+" "+Last+", "+Address+", "+City+", "+State+" "+Zip,lf()

The data is normally exported using UTF-8 encoding, but you can add a fourth parameter to specify alternate encodings. For example, if you wanted to import the data into an older version of Panorama (6.0 or earlier) you should use Mac OS Roman encoding, and you should also use carriage returns as the separator instead of linefeeds. If the current database is named Inventory, this example will export a text file named Inventory_export.txt, which contains a tab separated text export of all of the data in the Inventory database.

export info("databasename")+"_export.txt",exportline(),cr(),"Mac OS Roman"

Error Messages

Assorted error messages – If the formula supplied by the user contains an error, the operation is aborted and the error is returned.


See Also


History

VersionStatusNotes
10.0UpdatedCarried over from Panorama 6.0, but now includes an optional separator character and encoding type.