TRANS(), XLATE(), RTRANS() |
|
|
The TRANS() function returns a field or the entire record from a named data file. It is normally only used in dictionary I-type items. The synonym XLATE() may be used.
The RTRANS() function is similar but has a slight difference described below for closer compatibility with some other environments.
Format
TRANS({DICT} file.name, record.id, field, action) RTRANS({DICT} file.name, record.id, field, action)
where
In a QMBasic program, file.name is evaluated in the same way as any other expression. In a dictionary I-type record, the file.name may be specified with or without quotes. If file.name is an expression that evaluates to the file name, it must be enclosed in parentheses. In all usage, if the evaluated file name commences with DICT (case insensitive) separated from the actual name by a single space, the dictionary of the named file is used.
the name of a D or I-type item defined in the same dictionary which contains the id of the record to be retrieved. a literal record id enclosed in quotes.
A data item (A/C/D/E/I/S-type) defined in the target file's dictionary. If the field name does not follow the rules for construction of QMBasic variable names, it must be quoted. This form is not valid when the file.name is an expression. A field number @RECORD or -1 to return the entire record. If field is given as expression that evaluates to the field position, this must be enclosed in brackets to avoid potential syntactic ambiguity.
In addition,
The TRANS() function returns the specified data with any mark characters lowered by one level (e.g. value marks become subvalue marks).
If record.id is multivalued, the TRANS() function extracts each requested record and returns a multivalued result with the data from each record separated by a value mark.
The RTRANS() function is identical to TRANS() except that it does not lower the mark characters. This makes it impossible to distinguish between the results of retrieving a multivalued field from a single record and retrieving a single valued field from multiple records.
Examples
TOTAL.VALUE = QTY * TRANS('STOCK', PART.NO, 'PRICE', 'X')
The above statement used in a dictionary I-type record reads from the STOCK file a record (or list of records) whose id(s) can be found in the PART.NO variable. The X error code causes the TRANS() function to return a null value for any record that cannot be found. When using TRANS() in a QMBasic program, the field argument must be an expression that evaluates to the field number. For example: TOTAL.VALUE = QTY * TRANS('STOCK', PART.NO, 6, 'X')
X = TRANS(DICT 'ORDERS', 'DISCOUNT', -1, 'X') X = TRANS('DICT ORDERS', 'DISCOUNT', -1, 'X')
Both of the above statements perform the same action. Either might be used, for example, to retrieve a record named DISCOUNT from the dictionary of the ORDERS file. |