JavaScript Editor js editor     Web development 

Main Page

Conventionally, functions return values to the calling program. However, in Visual FoxPro, you can return values from procedures and functions. When procedures and functions do not include explicit RETURN statements that return a specified value, Visual FoxPro includes an implicit RETURN statement that returns a default value of True (.T.) automatically. Generally, you want to use the RETURN command to return a specified value from functions, for example, as a processing result or to indicate whether the function operation succeeded.

The RETURN command also returns control over code execution to the calling program. For more information, see RETURN Command.

In the following example, suppose you pass a date to the following function. The function returns a date that is 14 days later than the date that was passed:

В Copy Code
FUNCTION plus2weeks
   RETURN dDate + 14

You can then assign the return value from the function to a variable as shown in the following line of code:

В Copy Code
dDeadLine = plus2weeks(DATE())

Assigning Return Values from Procedures and Functions

You can assign values returned from procedures and functions explicitly, for example, to a variable, by using the equal sign (=) operator or pass the return value directly, for example, to another function.

In the following example, suppose the function myFunc returns a specific value. The first line of code assigns the return value from myFunc to a variable named myVar. The second line of code passes the return value from myFunc directly to a Visual FoxPro STR(В ) function, whose return value is then displayed to the current active output window using the ? command:

В Copy Code
myVar = myFunc( )
? STR( myFunc( ) )

See Also

JavaScript Editor js editor     Web development