Commands & Functions
Includes Examples
Fox SoftwareOverview of the Documentation
Getting Started introduces you to FoxPro and gives you a quick
tour of its powerful features. After the quick tour, you can continue
to the tutorial and learn how easy it is to use the features previewed
in the quick tour.
Interface Guide begins with an introduction to the interface
followed by an item-by-item tour of the interface. Each menu
option is described along with any related dialogs and windows.
FoxPro power tools, which allow you to build interface components
and access your data without programming, are also described in
this manual.
Commands & Functions is a complete reference for the FoxPro
Programming language. It contains detailed descriptions of all
FoxPro commands and functions in alphabetical order, plus an
alphabetical listing of system memory variables.
Developer's Guide contains an extended discussion of
recommended techniques for designing and implementing FoxPro
2.0 applications. Suggested usage of new FoxPro 2.0 power tools is
illustrated by numerous examples. Advanced. topics such as
customization, compatibility and optimization are also included in
this manual.
Help is always a keystroke away when you use FoxPro. To see
context-sensitive help for the active window, dialog or menu option,
press Fl. For a command, function or system memory variable,
select it and press Fl. Each help topic is linked with related help
topics for easy access,FoxPro’
Commands & Functions
‘August 191
Fox Software, Inc.
134 W. South Boundary
Perrysburg, Ohio 43551Trademarks
FoxBASE®, FoxBASE"+ and FoxBASE®+/Mac are registered trademarks and
FoxPro™ is a trademark of Fox Holdings, Inc. Other trademarks may be used
throughout this manual.
FoxPro software and reference materials are the sole property of Fox Holdings, Ine.
Reproductions of any kind without prior written consent is strictly prohibited.
© 1989, 1991 Fox Holdings, Inc. All rights reserved.Contents
Contents
The FoxPro Language
Using the FoxPro Language
‘The Command Window .
Creating Programs . . .
Saving Programs .. . .
Modifying Programs
Executing Programs nee
Additional Program Information . . .
FoxPro’s On-line Help Facility . . . .
Understanding the Language .
Commands and Functions
Command and Function Syntax Conventions . .
Expressions ........
Additional Abbreviations .
Record Range: Scope, For and While .
Database Work Areas .
Functions and Memo Fields... . . .
Typographic Conventions... ........
Commands and Functions iad sean
Data Types... . .:
Character Functions . . .
Numeric Functions . . . .
Date and Time Functions
Data Conversion
Databases . aoe
Field Manipulation . . . .
Database Manipulation
Record Manipulation .. . .
Indexes
Relations
2-12
2-13
2-14Programming ..........0..005 oe
Debugging and Error Handling .......
Program Execution
Structured Programming
Low-Level File Functions ... . .
Memory Variable Manipulation
Array Manipulation . oe
Event Handlers
Input and Output... . .
Data Formatting
Printing
Meau Bars and Popups
Windows
‘Typing, Keyboard and Mouse
Reports and Labels
FoxPro Environment . . .
Environment... . .
File Management
Network (FoxPro/LAN)
Network Commands and Functions.
Commands and Functions
This chapter contains complete descriptions of the
FoxPro commands and functions. The chapter is
organized alphabetically and begins on page 3-1.
System Memory Variables
‘This chapter contains complete descriptions of the
FoxPro system memory variables. The chapter is
organized alphabetically and begins on page 4-1.
Index
215
2-15
.. 216
.. 217
« . 2-18
+. 219
220
2. B21
« . 222
2 B22
«225
+ 226
«228
» » 230
.. 231
» » 232
~ . 232
. . 237
. 2-39
2-39
Contents1 The FoxPro Language
SS SS ae a MTN TE SETS
FoxPro is a product developed for data management — the catalog-
ing, tracking and processing of information. Although you can per-
form many database operations non-procedurally through the
menu system and interface, accessing FoxPro's tremendous power
requires some knowledge of the FoxPro programming language.
This chapter contains a variety of topics that will help you use the
FoxPro programming language, including an explanation of the
conventions used to describe the syntax of FoxPro commands and
functions.
FoxPro has an elegant user interface that makes data manage-
ment easy. While you use the interface, FoxPro commands that
correspond to your actions are generated in the Command window.
‘The Command window provides a gateway between the interface
and the FoxPro language.
The Command window contains a history of all the commands
created during an interactive FoxPro session, providing a means to
learn the FoxPro language. By examining the commands that are
generated when you use the interface, you can quickly learn the
language.
A command generated in the Command window can be re-executed
by moving the cursor to the line containing the command and
pressing Enter. After a long interactive FoxPro session, a lengthy
list of FoxPro commands is generated in the Command window.
You can copy and paste these commands into a FoxPro program.
A program can be repeatedly run, making it easy to execute literal-
ly thousands of commands again and again.
FoxPro programs, composed of FoxPro commands, provide in-
credible power to manipulate data. Access to the full power of
FoxPro is provided by the FoxPro language.
The FoxPro Language ChlUsing the FoxPro Language
Using the FoxPro Language
c12
The Command Window
A FoxPro command can be directly executed by typing it into the
Command window and pressing Enter. To re-execute a command,
move the cursor to the line containing the command with the
arrow keys or the mouse and press Enter.
Since the Command window is a special text editing window, you
can edit commands using FoxPro’s extensive editing tools. You can
edit, insert, delete, cut, copy or paste text within the Command
window.
For further information on the Command window, see the Window
Menu chapter in the FoxPro Interface Guide.
Creating Programs
A FoxPro program allows you to execute a series of commands you
enter into the program file.
Running a program has many advantages over ontering single
commands in the Command window:
* A> program allows you to execute many commands
automatically, saving time and lots of typing.
* The program can be modified and run again.
* Programs can run other programs,
* Certain structured programming commands are available only
in programs.
* FoxPro programs provide unparalleled performance.
FoxPro programs are text files containing a series of commands.
You can create a program in FoxPro in one of these ways:
* Choose New... from the File menu popup. The New File
dialog appears. Choose the Program radio button, then
choose OK.
* In the Command window, type the command MODIFY
COMMAND.
‘The FoxPro LanguageUsing the FoxPro Language
A new window named UNTITLED.PRG is opened. You can now
enter your program into this window. The program editing win-
dow supports all the standard FoxPro editing features. For help
on the FoxPro text editing features while in a text editing window,
press Fl.
If you have used FoxPro interactively and would like to save
the commands generated in the Command window, you can
) copy and paste them directly into the program editing win-
| dow. Program examples from the help file can also be
copied and pasted directly into a program. Copying program
examples from the help file is a quick and easy way to learn
how FoxPro commands and functions work.
Saving Programs
After you create your program, be sure to save it. To save your
untitled program, choose Save... or Save AS... from the File menu
popup. The Save As dialog appears, Once you save your program
you can execute the program or further modify it.
Modifying Programs
‘After you save your program, you can modify it. You must first
open the program. You can open a program in FoxPro in one of
these ways:
* Choose Open... from the File menu popup. A dialog appears
with a list of available files. From the Type popup, choose the
Program option. Choose the program you want to modify,
then choose OK.
* In the Command window, type the command MODIFY
COMMAND followed by a space and the name of the program to
modify, then press Enter. The program is opened for editing.
For example, to modify a program named MYPROGRM, enter
this command in the Command window:
MODIFY COMMAND myprogrm
After you open the program you can make changes. When you
finish making your changes, be sure to save the program.
The FoxPro Language C1-3Using the FoxPro Language
C1-4
Executing Programs
After you create a program, the program can be executed. To ex-
ecute a program you can:
* Choose the Do... option from the Program menu popup. From
the program list, choose the program to execute, then choose
OK.
* Type the command DO followed by a space and the name of
the program to execute, then press Enter. For example, to
execute the program named MYPROGRM, enter this command
in the Command window:
DO myprogem
Additional Program Information
For complete information on creating, editing and saving program
files, see the Text Editor section of the Interface Basics chapter in
the FoxPro Interface Guide. ‘Text editing features are also
described in the ™ Text Editing topic in the FoxPro on-line help
facility.
For information on executing program files, see the Program Menu
chapter in the FoxPro Interface Guide, the ® Do topic in the FoxPro
on-line help facility, or the DO command in this manual.
FoxPro’s On-line Help Facility
An on-line help facility is always available in FoxPro. ‘The on-line
help facility contains specific information on every FoxPro com-
mand, function and system memory variable and general informa-
tion about FoxPro. Context-sensitive help for the FoxPro interface
is also available.
‘To access on-line help, press F1 or choose the Help... option from
the System menu popup. The Help window is displayed with an
extensive list of topics. Choose a topic in the Help window for
details on the topic,
You can get help on related topics in the help facility by choosing
an option from the See Also popup. You can also sclect text in a
help topic and choose the Look Up push button. This allows you
to get help for a command or function by selecting the command or
function as it appears in a topic and choosing Look Up.
‘The FoxPro LanguageUsing the FoxPro Language
If the text you select is a help topic, help information appears for
the topic. Ifa help topic does not correspond to the text you select,
a dialog is displayed containing a list of help topics. The nearest
matching topic is selected. You can choose this topic or another
topic from the list.
To get help for a command or funetion in the Command window or
a program, select the command or function and press FL
Context-sensitive help is available for FoxPro system windows,
dialogs and system menu options. Press F1 when a system win-
dow or dialog is frontmost.
For further information on FoxPro's on-line help facility, see the
‘System Menu chapter in the FoxPro Interface Guide.
The FoxPro Language C15Understanding the Language
Understanding the Language
C16
Commands and Functions
The FoxPro language consists of two elements — commands and
functions. A command performs an action, a function returns a
value. For example, the BROWSE command lets you look at the
contents of a database. The DATE( ) function returns the system
date from your computer. Functions contain a pair of parentheses
that distinguish them from commands.
Commands and functions can be combined together to create a
FoxPro statement. Functions are not used by themselves, but are
always combined with a FoxPro command.
For example, the question mark (?) is a command that sends out-
put to the screen. DATE ) is a function that returns the current
system date. They can be combined to output the system date to
the sereen:
2 DATE( )
The STORE command assigns a value to a memory variable. In
this example, the TIME() function returns the current system time,
and this value is placed in the memory variable BEGINTIME:
STORE TIME( ) TO begintime
Command and Function Syntax Conventions
FoxPro commands and functions consist of one or more com-
ponents. These components determine how a command or function
can be used
Let’s look at the syntax of a typical FoxPro command. The
REPLACE command is used to update fields in a database record.
Here’s the syntax for the REPLACE command:
REPLACE
WITH [ADDITIVE]
[, WITH [ADDITIVE] ...
[] [FOR ] [WHILE ]
[NOOPTIMIZE]
‘The FoxPro LanguageUnderstanding the Language
‘The following table lists the components of the REPLACE command.
Component Examples in the REPLACE Command
REPLACE, WITH, ADDITIVE, FOR, WHILE,
NOOPTIMIZE
Expressions | exprl, expr2, expL1, expL2
field1, field2
‘This manual uses special typographic conventions in command and
function syntax. These conventions indicate whether a command
or function component should be entered as shown or supplied by
you, whether it is required or optional, and so on.
UPPER- UPPERCASE designates a FoxPro keyword. Every
CASE FoxPro command and function contains at least one
keyword. FoxPro uses keywords to identify a com-
mand or function. Keywords are sometimes called
reserved words since FoxPro reserves these special
words for internal use.
Some examples of keywords in the REPLACE command
are REPLACE (which FoxPro identifies as a command),
WITH, ADDITIVE, FOR and WHILE. WITH, ADDITIVE, FOR
and WHILE are referred to as clauses.
A keyword can be abbreviated to the first four charac-
ters.
<> Angle brackets < > surrounding lower-case text indi-
cate information that you must provide. This infor-
mation could be a file name, an expression, a memory
variable name and so on. You replace the text and
angle brackets with the appropriate name or expres-
sion.
() Parentheses must, be included in all FoxPro functions.
Include the parentheses as they appear in the
function's syntax.
The FoxPro Language 1-7Understanding the Language
C18
Expressions
Square brackets indicate a portion of a FoxPro com-
mand or function that’s optional. Do not type them.
For example, the REPLACE command supports
numerous options, and you have the choice of includ-
ing these options. The ADDITIVE, , FOR
, WHILE and NOOPTIMIZE clauses
and keywords are placed in square brackets to indi-
cate they are optional.
A vertical bar separating options indicates that you
can enter only one of the options.
An ellipsis indicates that a command or function or a
portion of a command or function can be continued in
a similar fashion. For example, the INLIST() function
supports a large number of arguments, The ellipsis in
the INLIST( ) syntax indicates that you can include
more arguments than the three listed.
A FoxPro expression is a combination of database field values,
functions, memory variable values, array element values, constants
and operators. There are four types of FoxPro expressions — char-
acter, numeric, date and logical.
Expressions are denoted in FoxPro commands and functions this
way:
Expression Expression type
| Character, Numeric, Date or Logical
| List of expressions separated by commas
The FoxPro LanguageUnderstanding the Language
When more than one expression of the same type appears in a
command or function, a number is added to indicate its position in
the command or function. For example, the syntax for the
CHRTRAN( ) function is:
CHRTRAN(, , )
CHRTRAN( ) requires three character expression arguments,
, and .
‘The database fields, functions, memory variables and array ele-
ments that are combined to create an expression must be of the
same data type. If they are of different type, FoxPro generates an
“Operator/operand type mismatch” error message.
Character Expressions
Character expressions are composed of the following:
* Character type database fields
* Functions that return character values
* Memory variables and array elements that contain character
data
* Character type constants, called string literals
A string literal is a character string surrounded by single or double
quotation mark. For example, ‘Ohio’ or “Ohio”. The quotation
marks must match. That is, you cannot begin a character string
with a single quotation mark and end it with a double quotation
mark.
You can imbed a quotation mark in a character string by sur-
rounding the character string with quotation marks of the opposite
type. For example, “Don’t touch!” is a legitimate string literal.
~ Throughout the FoxPro documentation you will see the null
\? string mentioned. The null string is a character string of
eg length 0 — it contains no characters.
The null string can be expressed with a pair of quotation marks
with no space between them —” or”
‘The FoxPro Language C19Understanding the Language
C110
Character Expression Operators
[operator | —————