Set Variable from External Database File

$lookup_var varname index indexfile datafile fieldname

This command sets a user variable from a value which is looked up in a dBASE-compatible data file, using the specified index, index value and field name. Note that the Extended Database Interface feature provides a much more comprehensive method of working with external databases.

The parameters on this command are used as follows:

varname the user or system variable name to which a value is to be assigned (written without @).
index the value which is to be used as an index to look up the record containing the data. This can either be a constant value or can be the contents of a variable using the normal @varname syntax.
indexfile the full pathname of the NDX file used as an index to look up the data. This can either be a constant value or can be the contents of a variable using the normal @varname syntax. See External Database Files for more information.
datafile the full pathname of the DBF file containing the data to be assigned. This can either be a constant value or can be the contents of a variable using the normal @varname syntax. See External Database Files for more information.
fieldname the dBASE field name of the field containing the data which is to be assigned. This can either be a constant value or can be the contents of a variable using the normal @varname syntax.

To reference .DBF files which have Clipper or FoxPro indexes, use the datafile parameter to specify a '.DD' file with the same basename as the .DBF file. This .DD file will then contain the name of the index file, and the indexfile parameter must be used to specify the name of the index tag in the specified index file.

If the record is not found or the named field does not exist in the data file, the look-up fails and control transfers to the $error_exit, if specified. If the index or data files do not exist, the .IIF file is treated as invalid and selecting it will fail. You should avoid specifying this command in an $auto_call infobox because this may be checked during COPIAFACTS startup before the index field has been initialized.

Examples:

Part of the implementation of a password control which requires a password to be entered which depends on the account number given at the start of the transaction:

$lookup_var password @cid callid.ndx callid.dbf mypass

$if @entered = @password

....

Look up a name and document count:

;00001010.IIF

$type decision

$lookup_var NAME @ID @FFBASE\nb\idlist.ndx @FFBASE\nb\idlist.dbf NAME

$lookup_var DOCCOUNT @ID @FFBASE\nb\idlist.ndx @FFBASE\nb\idlist.dbf DOCC

$next_box 1020

$error_exit s14

;00001020.IIF

$type decision

$if @DOCCOUNT <= 0 then

$next_box 1100

$else

$next_box 1099

$endif

;00001099.IIF

$type voice

$image_desc standard

$script "I'm sorry, but your allotment of documents"

$script "has run out. Please contact..."

$next_box s14