# How the EVALUATE() Function Works

ID: Q113172

The information in this article applies to:

- Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, and 2.5b
- Microsoft FoxPro for Windows, versions 2.5, 2.5a, and 2.5b
- Microsoft FoxPro for Macintosh, version 2.5b

## SUMMARY

The EVALUATE() function evaluates the expression contained within the parentheses and returns the result. However, the EVALUATE() function produces different results based on the exact syntax of the statement.

## MORE INFORMATION

The EVALUATE() function returns different values based on whether quotation marks ("") are placed around the expression being evaluated. Enclosing the expression within quotation marks causes EVALUATE() to return the literal value of the expression. However, if no quotation marks are used, the command returns the value stored in the expression.

To demonstrate this behavior, type the following in the Command window:

       x = "Level1"
       Level1 = "Level2"
       ? EVALUATE("X")    && "Level1" appears on the screen
       ? EVALUATE(X)      && "Level2" appears on the screen.

As you can see, quotation marks determine what value the EVALUATE() function returns. With the quotation marks, EVALUATE() returns the literal value of the expression; in this case, "Level1". Without the quotation marks, EVALUATE() returns the value contained within the expression being evaluated; in this case, "Level2".

Since the function returns quite different values based on its syntax, it may cause various error messages to appear, depending on the program's code. For example, the following code returns the error "Index Does Not Match Database File. Recreate Index":

       IF _MAC
          USE tutorial\customer SHARE
       ELSE
          USE c:\<foxpro directory>\tutorial\customer.dbf SHARE
       ENDIF
       BROWSE NOWAIT
       PUBLIC ord
       ord="Company"
       INDEX ON EVALUATE(ord) TO test.idx
       APPEND BLANK
       REPLACE Company WITH 'test company"
       SHOW WINDOW CUSTOMER REFRESH

Since the EVALUATE() function in this example does not contain quotation marks around the variable "ord", the literal value "company" is not returned. Instead, EVALUATE(ord) returns the value of the COMPANY field of the current record, which causes the error messages.

## REFERENCES

"Commands & Functions," version 2.0 (MS-DOS), page C3-356 "Language Reference," version 2.5 (MS-DOS and Windows), page L3-485 "Language Reference," version 2.5 (Macintosh), page 407

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b macro substitution KBCategory: kbprg KBSubcategory: FxprgMacrosub

Last Reviewed: June 27, 1995 © 1999 Microsoft Corporation. All rights reserved. Terms of Use.