You receive the "Syntax error" error message when you verify the user-defined function in Report Writer in FoxPro (113754)
The information in this article applies to:
- Microsoft Visual FoxPro for Windows 3.0
- Microsoft FoxPro for MS-DOS 2.0
- Microsoft FoxPro for Macintosh 2.6a
- Microsoft FoxBASE+ for MS-DOS 2.1
This article was previously published under Q113754 SUMMARY
When you are verifying an user-defined function (UDF) in the Expression
Builder, a "Syntax Error" appears. The "Syntax Error" message occurs
because the Expression Builder cannot evaluate UDFs and expects instead to
find an internal function.
However, if the UDF() function exists as a stand-alone .PRG file and has
previously been tested, the function will operate properly in a report when
the report is previewed or printed.
MORE INFORMATION
A UDF is a program routine that must always return a value of some type. It
can be created in two forms: external and internal. An internal function is
a subroutine within a .PRG file, and its name must be preceded with the
FUNCTION statement. An external function is a single .PRG file, with a
maximum of eight characters for its name.
The external form must be used so that the Report Writer can find it as a
stand-alone .PRG file in the default directory or SET PATH list (SET
PROCEDURE TO is not evaluated).
Once you have created the function, you can test the function by invoking
it from the Command window or from within a program. In the following
example, a function to print a time stamp (minute resolution) on each
record is needed. To do this, create the file STAMP.PRG, which contains
this single line:
RETURN LTRIM(STR(SECONDS()/60))+':'+LTRIM(STR(SECONDS()%60,10,3))
This function returns the number of seconds since midnight divided by 60 to
show the number of minutes (no decimals), concatenated with the modulus of
SECONDS to show the remainder of seconds and hundredths of seconds. To test
this function, type the following commands in the Command window:
SET TALK ON && if not on already
? Stamp()
FoxPro should return a character string consisting of the minutes, a colon,
the seconds, a decimal point, and the hundredths of seconds. Although the
function name is STAMP, it must be invoked as STAMP() to cause FoxPro to
look for an internal function of the same name. When it cannot be found,
FoxPro will then look externally for a file with the same name.
After the function has been successfully tested, you can use it in the
report. To use the function, create a field on the report and enter the
name of the function followed by a left and right parentheses, as shown in
the test above.
Modification Type: | Major | Last Reviewed: | 2/16/2005 |
---|
Keywords: | kberrmsg KB113754 |
---|
|