Partager via


PROGRAM( ) Function

Returns the name of the program at a specified program level, the name of the currently executing program, the current program level, or the name of the program executing when an error occurred.

PROGRAM([nLevel])

Parameters

  • nLevel
    Specifies the number of program levels to search for the program name. The nLevel parameter can range from 0 to the program nesting depth. For more information about program nesting levels, see maximum number of DO calls in Visual FoxPro System Capacities.

    When nLevel is omitted, PROGRAM( ) returns the name of the currently executing program. If you specify 0 or 1 for nLevel, PROGRAM( ) returns the name of the master program, or the highest-level program.

    If you specify –1 for nLevel, PROGRAM( ) returns the current program level as a numeric value. However, using PROGRAM(–1) in the Command window always returns zero (0).

    If nLevel exceeds the program nesting depth, PROGRAM( ) returns an empty string ("").

Return Value

Character or Numeric. PROGRAM( ) returns a program name, the number of the current program level, or an empty string.

Remarks

You can use PROGRAM( ) to help your program recover from errors. The PROGRAM( ) function is similar to SYS(16) - Executing Program File Name.

Example

ON ERROR DO errhand WITH PROGRAM( )

** The next line should generate an error ** USE nodatabase ON ERROR && Returns to system default error-handling routine PROCEDURE errhand PARAMETERS gcProgram WAIT 'An error occurred in the program ' + gcProgram WINDOW

See Also

Reference

DO Command

LINENO( ) Function

MESSAGE( ) Function

ASTACKINFO( ) Function

Other Resources

Functions