Chapter 9 : Language and Code Examples
Microsoft FoxPro Support Engineers
Microsoft Corporation
Created: December 15, 1993
Abstract
This section discusses Microsoft FoxPro for Windows version 2.5x programming language and contains the following topics:
·	Introduction
·	New Clauses
·	Listing of Common, New or Updated Commands
·	Code Samples
·	Additional Information
Introduction
Many new commands were added to the FoxPro language to take advantage of the graphical environment of Microsoft Windows. Changes were also made to existing commands and functions to enable manipulation of fonts, styles, printing options and colors. Below is a listing of new and updated commands. Listed as well are some of the more common FoxPro commands and functions.
New Clauses
To some existing commands and functions, these new clauses were added:
·	FONT and STYLE
·	PROMPT
·	RGB
FONT and STYLE
Here are a few things to keep in mind when using FONT and STYLE clauses:
FONT
·	If you include the FONT clause but omit the font size, a 10 point font is used.
·	If the FONT clause is omitted and output is placed in the main FoxPro window, the Main FoxPro window, or “screen font” is used for output.
·	If the FONT clause is omitted and output is placed in a user-defined window, the user-defined window font is used for the output. 
·	If the font you specify is not available, Windows substitutes a font with similar font characteristics.
STYLE
·	Include the STYLE clause to specify a STYLE for output.
·	The styles that are available for a font are determined by Windows. If the font style you specify is not available, Windows substitutes a font style with similar characteristics.

Character	Font Style	
B	Bold	
I	Italic	
N	Normal	
O	Outline	
Q	Opaque	
S	Shadow	
--	Strikeout	
T	Transparent	
U	Underline	

PROMPT
You can include the optional PROMPT clause to display a dialog before printing starts. Place the PROMPT key word immediately after TO PRINTER. In this dialog you can adjust printer settings, specify the number of copies and specify page numbers to print.
NOTE:     The printer dialog box displayed by the PROMPT clause contains a To File check box. You cannot use this To File option to send a graphics-based report created in FoxPro for Windows to a text file. To send output to a file, set the default printer in Windows Control Panel/Printers to Generic Text Only to File.
RGB
In FoxPro for Windows, a color pair can be specified with a set of 6 RGB (Red, Green, Blue) color values separated by commas. The first 3 color values specify the foreground color and the second 3 color values specify the background color. The color values can range from 0 through 255. An example of syntax would be RGB(255,0,0,255,255,255).
TIP:     Two ways to determine what color the RGB values translate to are
·	Use Windows Control Panel\ Colors
·	Run Paintbrush and double click on a color on the palette. You can then scale the values up and down and see the resulting output color.
Listing of Common, New and Updated Commands and Functions

Command/ Function	New	FONT/ STYLE	PROMPT	RGB	More Information	Code Example	
?|??		X				X	
@...BOX						X	
@...EDIT -- Text editing regions		X		X	Q103089	X	
@...FILL				X	Q104328		
@...GET		X		X			
@...GET -- Check Boxes		X		X	Q98927		
@...GET -- Invisible Buttons				X			
@...GET -- Lists		X		X	Q98927, Q103605, Q95377		
@...GET --Popups		X		X	Q103089		
@...GET --Push Buttons		X		X	Q98773, Q96356	X	
@...GET --Radio Buttons		X		X	Q98927		
@...GET --Spinners	X	X				X	
@...SAY		X		X	Q99556	X	
@...SAY-BMP & OLE Objects	X				Q101004, Q103597, Q103692, Q97629		
@...PATTERN	X						
@...TO				X			
ACTIVATE MENU						X	
ADIR()						X	
AELEMENT()						X	
AFIELDS()						X	
AFONT()	X				Q99543	X	
ALEN()						X	
ALLTRIM()						X	
ANSITOOEM()	X				Q99083		
APPEND						X	
APPEND GENERAL	X				Q101018		
ASCAN()						X	
ASORT()						X	
BROWSE		X		X	Q104005, Q104593		
CHANGE		X		X	Q98689		
COPY FILE						X	
COPY STRUCTURE EXTENDED						X	
COPY TAG						X	
DDEAbort Trans()	X						
DDEAdvise()	X				Q103589		
DDEEnable()	X						
DDEExecute()	X				Q103087, Q98351, Q103087, Q103587		
DDEInitiate()	X				Q105005		
DDELastError()	X						
DDEPoke()	X					X	
DDERequest()	X				Q97164		
DDESetOption()	X						
DDESetService()	X						
DDESetTopic()	X						
DDETerminate()	X						
DECLARE						X	
#DEFINE... #UNDEF	X						
DEFINE MENU						X	
DEFINE POPUP						X	
DEFINE WINDOW -- other		X		X	Q97641, Q95705, Q95305, Q95243, Q95707, Q95375		
DIR |DIRECTORY			X				
DISPLAY			X				
DISPLAY FILES			X			X	
DISPLAY MEMORY			X		Q104476		
DISPLAY STATUS			X				
DISPLAY STRUCTURE			X				
DO CASE.. ENDCASE						X	
DO WHILE						X	
DTOC()						X	
DTOS()						X	
EDIT		X		X			
EVALUATE()						X	
FILE()						X	
FLOCK()						X	
FONTMETRIC()	X				Q94350		
FOPEN()						X	
FSIZE()						X	
GATHER						X	
GETDIR()	X						
GETFONT()	X				Q95587		
#IF...#ELIF...#ENDIF	X						
IIF()						X	
LABEL			X				
MODIFY GENERAL	X						
MODIFY WINDOW	X				Q96360	X	
MOVE WINDOW						X	
OBJNUM()						X	
OEMTOANSI()	X						
ON ERROR						X	
ON SHUTDOWN	X				Q104325		
PROCEDURE						X	
RDLEVEL()						X	
REGIONAL						X	
REPLACE					Q96369	X	
REPLICATE()						X	
REPORT			X				
RGBSCHEME()	X						
SELECT - SQL						X	
SET BRSTATUS						X	
SET EXCLUSIVE						X	
SET KEYCOMP	X						
SET NOCPTRANS	X					X	
SET PALETTE	X						
SET PRINTER FONT	X						
SET STATUS BAR	X				Q93585		
SET WINDOW OF MEMO						X	
SHOW GET						X	
SKPBAR()						X	
SKPPAD()						X	
SOUNDEX()						X	
STR()						X	
STRTRAN()						X	
STUFF()						X	
SUBSTR()						X	
SYS(1001)						X	
SYS(1016)						X	
SYS(2003)	X				Q86908		
SYS(2004)	X						
SYS(2005)	X						
SYS(2006)	X						
SYS(2011)						X	
SYS(2013)	X						
SYS(2019)	X						
SYSMETRIC()	X					X	
TRANSFORM()						X	
TYPE			X				
TXTWIDTH()	X						
VAL()						X	
VARREAD()						X	
WFONT()	X				Q95231		
WOUTPUT()					Q97640	X	
_BEAUTIFY	X				Q103778		
_CUROBJ					Q96356, Q96358, Q98443, Q99549	X	
_DOS	X						
_MAC	X						
_ORACLE	X				Q100801		
_SQLSERVER	X				Q93628		
_SPELLCHK	X				Q95369, Q104325		
_TRANSPORT	X						
_UNIX	X						
_WINDOWS	X						
Coding Examples
? ?? 
The following example combines the ? and ?? commands to demonstrate how the ? command sends a carriage return and line feed. It also shows how a PICTURE clause can be used to format the output. 
SET TALK OFF 
Name="David" 
Phone= 1234567890 
? "The phone number for " 
?? Name 
? "is " 
?? Phone PICTURE '(999) 999-9999' 
The output from the previous code is below. 
The phone number for David 
is (123) 456-7890 
@ BOX 
This command draws a box on the main FoxPro window in FoxPro for Windows, or in a user defined window.
@ 1,1,5,5 BOX 'C' 
The following example brings up a window that allows you to enter the top corner coordinate of a box, the bottom corner of a box and the character that the box should be drawn with. The program then proceeds to erase the window that was displayed to get the information and draws the box on the desktop.
** DON'T ECHO INFORMATION TO THE SCREEN 
** WHEN VARIABLES ARE INITIALIZED 
SET TALK OFF 
 
** DEFINE A WINDOW TO GET THE INFORMATION FROM 
DEFINE WINDOW getinfo FROM 1,1 TO 20,60 TITLE 'ENTER INFORMATION FOR 
DRAWING BOX' 
ACTIVATE WINDOW getinfo 
 
** INITIALIZE THE VARIABLES TO 0 
X1=0 
Y1=0 
 
X2=0 
Y2=0 
 
** THIS IS AN OPTIONAL PARAMETER 
DRAWCHAR=SPACE(1) 
 
** GET THE COORDINATES OF THE UPPER LEFT HAND CORNER, 
** THE LOWER RIGHT HAND CORNER OF THE BOX, AND IF THE 
** BOX SHOULD BE DRAWN WITH A SPECIFIC CHARACTER. 
 
MODIFY WINDOW SCREEN FONT "FoxFont", 10 
@ 1,2 SAY "UPPER LEFT CORNER X COORDINATE -X1:" GET X1 SIZE 1,3 
@ 3,2 SAY "UPPER LEFT CORNER Y COORDINATE -Y1:" GET Y2 SIZE 1,3 @ 5,2 SAY "LOWER RIGHT CORNER X COORDINATE-X2:" GET X2 SIZE 1,3 
@ 7,2 SAY "LOWER RIGHT CORNER Y COORDINATE-Y2:" GET Y2 SIZE 1,3 
@ 9,2 SAY "CHARACTER TO DRAW BOX WITH(LEAVE BLANK FOR LINE):" GET cDRAWCHAR 
READ 
 
** RELEASE THE WINDOW FROM MEMORY AND CLEAR IT FROM SCREEN. 
RELEASE WINDOW getinfo 
 
** CHECK TO SEE IF THE DRAWCHAR, THE CHARACTER USED TO DRAW BOX, IS 
** BLANK. IF DRAWCHAR HAS BEEN LEFT BLANK, THEN WE WILL JUST USE THE 
** REGULAR LINE TO DRAW THE BOX. DRAW THE BOX. 
IF cDRAWCHAR=" " 
 @ X1,Y1,X2,Y2 BOX 
ELSE 
 cDRAWCHAR="'"+cDRAWCHAR+"'" 
 @ X1,Y1,X2,Y2 BOX &cDRAWCHAR 
ENDIF 
@ EDIT 
The following example creates a screen using the customer database. It contains several example of @...EDITs. Clauses used are; SIZE, DEFAULT, DISABLE, MESSAGE, VALID, WHEN, NOMODIFY, SCROLL, TAB, AND COLOR. The control button moves you through the screen. 
SET TALK OFF && Keep info from displaying on screen 
USE customer.dbf && Open up the Customer database 
PUBLIC bottomrec, toprec 
GO BOTTOM && Goto the last record bottomrec=RECNO() 
&& Set variable bottomrec equal to last record number 
GO TOP && Goto the first record toprec=RECNO() 
&& Set variable toprec equal to the first record 
choice=" " && Initialize variables choice, and lastedit to blank 
lastedit=" " 
&& Define and activate window 'editor' 
DEFINE WINDOW editor FROM 0,0 TO 23,73 FLOAT NOCLOSE MINIMIZE TITLE ;
"@...EDIT Example" 
ACTIVATE WINDOW editor 
@ 0,7 SAY "CNO" && Title of field1 
&& Field1 is defined with only clauses size, and default 
@ 1,7 EDIT customer.CNO SIZE 1,7,5 DEFAULT " " 
@ 3,7 SAY "Company" && Title of field2 
&& Field2 is disabled 
@ 4,7 EDIT customer.company SIZE 1,35,15 DEFAULT " " DISABLE 
@ 6,7 SAY "Contact" && Title of field3 && Field3 is scrollable 
@ 7,7 EDIT customer.contact SIZE 4,20,10 SCROLL NOMODIFY ;
MESSAGE "You may not modify this field" 
@ 6,29 SAY "Address" && Title of field4 
&& Field4 can be tabbed within 
@ 7,29 EDIT customer.address SIZE 4,40,27 DEFAULT " " TAB COLOR ,GR+/B,,,,W+,,,,W/B 
&& Message to select field5 to see contents 
@ 13,7 SAY "Click on this field to see the contents." 
&& Field5 is using tab, scroll, picture, when, valid, and && default clauses 
@ 14,7 EDIT lastedit SIZE 3,60,27 PICTURE "@K" DEFAULT " " TAB ;
SCROLL WHEN lastwhen() VALID lastval() 

&& Control buttons 
@ 20,7 GET choice PICTURE "@*HN \<Next;Pr\<ior;\<Top;\<Bottom;\?\!\<Close" ; 
 SIZE 2,10,1 DEFAULT 1 STYLE "B" VALID ctrlval() 
 
READ CYCLE 
 
RELEASE ALL && Clear everything 
CLOSE ALL 
CLEAR ALL 
CLEAR 

FUNCTION lastwhen && lastedit WHEN 
 
lastedit=ALLTRIM(city)+chr(13)+ALLTRIM(REGION)+chr(13)+ ;
ALLTRIM(postalcode)+chr(13)+ALLTRIM(country) 
SHOW GETS 

FUNCTION lastval && lastedit VALID 
 #REGION 1 
 WAIT WINDOW "You have selected the last edit region!" NOWAIT 
 
FUNCTION ctrlval && choice VALID - Control buttons 
setup 
 #REGION 1 
 DO CASE 
 CASE choice = "Next" 
 SKIP 1 
 IF RECNO() = bottomrec 
 SHOW GET choice, 1 DISABLE 
 SHOW GET choice, 4 DISABLE 
 ELSE 
 IF RECNO() > toprec 
 SHOW GET choice, 2 ENABLE 
 SHOW GET choice, 3 ENABLE 
 ENDIF 
 ENDIF 
 CASE choice = "Prior" 
 SKIP -1 
 IF RECNO() = toprec 
 SHOW GET choice, 2 DISABLE 
 SHOW GET choice, 3 DISABLE 
 ELSE 
 IF RECNO() < bottomrec 
 SHOW GET choice, 1 ENABLE 
 SHOW GET choice, 4 ENABLE 
 ENDIF 
 ENDIF 
 CASE choice = "Top" 
 GO TOP 
 SHOW GET choice, 1 ENABLE 
 SHOW GET choice, 2 DISABLE 
 SHOW GET choice, 3 DISABLE 
 SHOW GET choice, 4 ENABLE 
 CASE choice = "Bottom" 
 GO BOTTOM 
 SHOW GET choice, 1 DISABLE 
 SHOW GET choice, 2 ENABLE 
 SHOW GET choice, 3 ENABLE 
 SHOW GET choice, 4 DISABLE 
 CASE choice = "Close" CLEAR READ 
 ENDCASE 
SHOW GETS 
@ GET PUSH BUTTON
This example shows how to:
·	Create a DO CASE statement to manipulate push buttons
·	Disable/enable push buttons
·	Create Hot Key/Default Key push buttons
·	Move to the second push button in a group of buttons
·	Change the PROMPT of a push button programmatically. 

SET TALK OFF 
 
IF _DOS=.T. 
 DEFINE WINDOW exbutton FROM 5,10 TO 17,69; 
 TITLE " Example of Push Buttons "; 
 COLOR SCHEME 1 
 * By making Changeme and cMchoice both character * 
 * you use the PROMPT names in your DO CASE * 
 * statement. Variables for Push Buttons are * 
 * numeric by default. * 
 Changeme=" " 
 Mchoice=" " 
 Flname=SPACE(30) 
 
 ACTIVATE WINDOW exbutton 
 @ 1,6 SAY "Enter Your Name:" SIZE 1,16 
 @ 3,5 SAY "Press this button to Change Push Button Prompt" ; 
 SIZE 1,50 
 @ 7,3 SAY "Press CTRL+ENTER to select Default Push Button Prompt" ; 
 SIZE 1,53 
 @ 1,24 GET Flname SIZE 1,30 VALID undim() 
 
 * Below is a standard Push Button example * 
 @ 5,21 GET Changeme PICTURE "@*HN Unchanged"; 
 SIZE 1,15 VALID chgprompt() 
 
 * Below is a standard multi-prompt push button. * 
 * Clear and Quit are enabled while Save is * 
 * disabled with the "\\". The letters "l" and * 
 * "Q" are short cut keys by putting "\<" in * 
 * front of the letters. The Quit prompt is the * 
 * default push button with "\!" at the * 
 * beginning of the word. * 
 @ 9,5 GET Mchoice ; 
 PICTURE "@*HN C\<lear;\\Save;\!\<Quit" ; 
 SIZE 1,15,1 ; 
 DEFAULT 1 ; 
 VALID options() 
 
 READ CYCLE 
 CLEAR 
 RELEASE WINDOW EXBUTTON 
 SET TALK ON 
ELSE 
 DEFINE WINDOW exbutton FROM 5,10 TO 20,69; 
 TITLE " Example of Push Buttons "; 
 COLOR SCHEME 1 SYSTEM Font "MS Sans Serif" Style "B" 
 * By making Changeme and cMchoice both character * 
 * you use the PROMPT names in your DO CASE * 
 * statement. Variables for Push Buttons are * 
 * numeric by default. * 
 Changeme=" " 
 Mchoice=" " 
 Flname=SPACE(30)  
 ACTIVATE WINDOW exbutton 
 @ 1,6 SAY "Enter Your Name:" SIZE 1,16 
 @ 3,8 SAY "Press this button to Change the Push Button Prompt" ; 
 SIZE 1,54 
 @ 8,3 SAY "Press CTRL+ENTER to select Default Push Button Prompt" ; 
 SIZE 1,53 
 @ 1,24 GET Flname SIZE 1,30 VALID undim() 
 
 * Below is a standard Push Button example * 
 @ 5,21 GET Changeme PICTURE "@*HN Unchanged"; 
 SIZE 2,15,1 VALID chgprompt() 
 
 * Below is a standard multi-prompt push button * 
 * Clear and Quit are enabled and Save is * 
 * disabled with the "\\". The letters "l" and * 
 * "Q" are short cut keys by putting "\<" in * 
 * front of the letter. The Quit prompt is the * 
 * default push button with "\!" at the * 
 * beginning of the word. * 
 @ 10,5 GET cMchoice ; 
 PICTURE "@*HN C\<lear;\\Save;\!\<Quit" ; 
 SIZE 2,15,1 ; 
 DEFAULT 1 ; 
 VALID options() 
 
 READ CYCLE 
 RELEASE WINDOW EXBUTTON 
 SET TALK ON 
ENDIF 
 
FUNCTION options && cMchoice VALID 
DO CASE 
CASE Mchoice="Clear" 
 Flname=SPACE(30) 
 _CUROBJ=OBJNUM(Flname) 
 SHOW GET Mchoice,2 DISABLE 
 SHOW GETS 
CASE Mchoice="Save" 
 WAIT WINDOW "Record has been saved" TIMEOUT 2 
CASE Mchoice="Quit" 
 CLEAR READ 
ENDCASE 
 
FUNCTION chgprompt && Changeme VALID 
* In this valid we determine what the 
* current prompt is equal to and change 
* it to the opposite value. 
IF Changeme="Unchanged" 
 SHOW GET Changeme,1 PROMPT 'Changed' 
ELSE 
 SHOW GET Changeme,1 PROMPT 'Unchanged' 
ENDIF 
RETURN .T. 
 
FUNCTION undim && Flname VALID 
* This valid statement checks to see if 
* data has been entered into the field. 
* If data is entered then it enables the 
* Save push button and makes it the 
* current object. * 
IF !EMPTY(Flname) 
 SHOW GET Mchoice,2 PROMPT '\<Save' ENABLE 
 _CUROBJ=OBJNUM(Mchoice)+1 
ENDIF 
RETURN .T.
@ GET SPINNER 
To facilitate precise positioning of a spinner in the main FoxPro window or in a user-defined window, you can use decimal positions for row and column coordinates in FoxPro for Windows. 
@ 2.385, 2.718 GET Mchoice SPINNER 1, 1, 10 DEFAULT 3 
READ 
@ SAY 
The SAY command is used to output information to the screen. This example demonstrates the use of each of the clauses on the @ ... SAY. 
CLEAR 
@ 1,1 SAY "Test" 
WAIT WINDOW "" TIMEOUT 1 
 
* [FUNCTION <expC1>] 
 
* Function Codes 
* Code Purpose 
* B Left-justifies numeric data within the display region. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 say X FUNCTION "B" 
WAIT WINDOW "" TIMEOUT 1 
 
* C CR is displayed after a positive number to indicate a 
* credit. Can be used with numeric data only. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "C" 
WAIT WINDOW "" TIMEOUT 1 
 
* D Uses the current SET DATE format. 
 
CLEAR 
cMdatefmt=SET("DATE") 
SET DATE TO ANSI 
cMdate="93/10/01" 
@ 1,1 SAY cMdate 
@ 2,1 SAY cMdate FUNCTION "D" 
WAIT WINDOW "" TIMEOUT 1 
SET DATE (cMdatefmt) 
 
* E Edits date type data as a BRITISH date. 
 
CLEAR 
cMdatefmt=SET("DATE") 
SET DATE TO ANSI 
cMdate=DTOC(DATE()) 
@ 1,1 SAY cMdate 
@ 2,1 SAY cMdate FUNCTION "E" 
WAIT WINDOW "" TIMEOUT 1 
SET DATE (cMdatefmt) 
 
* T Trim leading and trailing blanks from <expr>.  
CLEAR 
cMtext = " This is a text string " 
@ 1,1 SAY cMtext 
@ 2,1 SAY cMtext FUNCTION "T" 
WAIT WINDOW "" TIMEOUT 1 

* X DB is displayed after negative numbers to indicate a 
* debit. Use only with numeric data. 
 
CLEAR 
X=-1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "X" 
WAIT WINDOW "" TIMEOUT 1 
 
* Z <expr> is displayed as all blanks if its numeric value 
* is 0. Use only with numeric data. 
 
CLEAR 
X=0.00 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "Z" 
WAIT WINDOW "" TIMEOUT 1 
 
* ( Encloses negative numbers in parentheses. Use only 
* with numeric data. 
 
CLEAR 
X=-1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "(" 
WAIT WINDOW "" TIMEOUT 1 
 
* ! Converts alphabetic characters to upper-case. Use with
* character data only. 
 
CLEAR 
cMtext = "This is a text string" 
@ 1,1 SAY cMtext 
@ 2,1 SAY cMtext FUNCTION "!" 
WAIT WINDOW "" TIMEOUT 1 
 
* ^ Displays numeric data using scientific notation. Use 
* with numeric data only. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "^" 
WAIT WINDOW "" TIMEOUT 1 
 
* $ Displays data in currency format. The currency symbol 
* appears before or after the field value depending on the 
* current setting of SET CURRENCY. Use with numeric data
* only. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X FUNCTION "$" 
WAIT WINDOW "" TIMEOUT 1 
 
* [PICTURE <expC2>] 
 * A PICTURE expression can include any characters, but only the characters
* listed below actively participate in display and printing. 
 
* Picture Codes 
* Code Purpose 
* X Allows any character. 
 
CLEAR 
cMtext = "This is a text string" 
@ 1,1 SAY cMtext 
@ 2,1 SAY cMtext PICTURE "XXXX" 
WAIT WINDOW "" TIMEOUT 1 
 
* Y Allows logical Y, y, N and n only. Converts y and n to
* Y and N, respectively. 
 
CLEAR 
cMconfirm= "n" 
@ 1,1 SAY cMconfirm 
@ 2,1 SAY cMconfirm PICTURE "Y" 
lMconfirm =.T. 
@ 3,1 SAY lMconfirm PICTURE "Y" 
WAIT WINDOW "" TIMEOUT 1 
 
* ! Converts lower-case letters to upper-case letters. 
 
CLEAR 
cMtext = "This is a text string" 
@ 1,1 SAY cMtext 
@ 2,1 SAY cMtext PICTURE "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 
WAIT WINDOW "" TIMEOUT 1 
 
* $ Displays the current currency symbol specified by SET CURRENCY. By default,
* the symbol is placed immediately before or after the field. However, the 
* currency symbol and its placement (SET CURRENCY), the separator character
* (SET SEPARATOR) and the decimal character (SET POINT) can all be changed. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X PICTURE "$ 9999.99" 
@ 3,1 SAY X PICTURE "@$" 
 
WAIT WINDOW "" TIMEOUT 1 
 
* * Asterisks are displayed in front of the numeric value. 
* Use with a dollar sign $ for check protection. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X PICTURE "* 9999.99" 
WAIT WINDOW "" TIMEOUT 1 
 
* . Specifies the decimal point position. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X PICTURE "9999.999" 
WAIT WINDOW "" TIMEOUT 1 
 
* , Use to separate digits to the left of the decimal point. 
 
CLEAR 
X=1235.67 
@ 1,1 SAY X 
@ 2,1 SAY X PICTURE "9,999.99" 
WAIT WINDOW "" TIMEOUT 1 
 
* [SIZE <expN1>, <expN2>] 
 
CLEAR 
mtext = "This is a text string" 
@ 1,1 SAY mtext 
@ 2,1 SAY mtext SIZE 3,10 
WAIT WINDOW "" TIMEOUT 1 
 
* [FONT <expC3> [, <expN3]] - Windows ONLY 
 
CLEAR 
mtext = "This is a text string" 
@ 1,1 SAY mtext 
@ 2,1 SAY mtext FONT "ARIAL",18 
WAIT WINDOW "" TIMEOUT 1 
 
* [STYLE <expC4>] - Windows ONLY 
 
CLEAR 
mtext = "This is a text string" 
@ 1,1 SAY mtext 
@ 2,1 SAY mtext FONT "ARIAL",18 STYLE "B" 
WAIT WINDOW "" TIMEOUT 1 
 
* [COLOR SCHEME <expN4> 
 
CLEAR 
mtext = "This is a text string" 
@ 1,1 SAY mtext 
@ 2,1 SAY mtext COLOR SCHEME 7 
WAIT WINDOW "" TIMEOUT 1 
 
* | COLOR <color pair list>] 
 
CLEAR 
mtext = "This is a text string" 
@ 1,1 SAY mtext 
@ 2,1 SAY mtext COLOR N/W+ 
WAIT WINDOW "" TIMEOUT 1 
ACTIVATE MENU 
This program will create and activate a menu with two bars.
DEFINE MENU test BAR AT LINE 1 
 
DEFINE PAD one OF test PROMPT '\<One' 
DEFINE PAD two OF test PROMPT '\<Two' 
 
ON PAD one OF test ACTIVATE POPUP one 
ON PAD two OF test ACTIVATE POPUP two 
 
DEFINE POPUP one 
DEFINE BAR 1 OF one PROMPT "A" 
DEFINE BAR 2 OF one PROMPT "B" 
DEFINE BAR 3 OF one PROMPT "C" 
ON SELECTION POPUP one DO onechoice 
DEFINE POPUP two 
DEFINE BAR 1 OF two PROMPT "D" 
DEFINE BAR 2 OF two PROMPT "E" 
DEFINE BAR 3 OF two PROMPT "F" 
ON SELECTION POPUP two DO twochoice 
 
ACTIVATE MENU test 
DEACTIVATE MENU test 
RELEASE MENU test EXTENDED 
SET SYSMENU TO DEFAULT 
 
PROCEDURE onechoice 
WAIT WINDOW "You Picked a bar from Pad 1" 
 
PROCEDURE twochoice 
WAIT WINDOW "You Picked a bar from Pad 2" 
ADIR() 
The following example uses the ADIR() function to automatically open all of the FoxPro .DBF tables in the current directory 
* Variables: 
* DBFArray() is an array that contains information returned from ADIR 
* NumTables is a numeric variable, containing the number of .DBF's found 
* Index is a numeric, used to specify which element to look at in the FOR loop.
 
CLEAR 
CLOSE DATABASES 
DIMENSION DBFArray(1) && Create array to hold drive info 
numtables = ADIR(DBFArray, '*.DBF') && Use ADIR() to fill the array 
 
IF NumTables > 0 
 FOR index = 1 TO NumTables 
 SELECT 0 
 USE (DBFArray(Index,1)) 
 ? "Opened "+ALLTRIM(DBFArray(Index,1))+" in work area 
"+ALLTRIM(STR(SELECT())) 
 ENDFOR 
ELSE 
 ? "There were no .DBF files to open in this directory." 
ENDIF 
AELEMENT()
AELEMENT() returns the number of an element in an array when given the row and column of the array element. The following example creates an array based on the fields, CNO and COMPANY, in CUSTOMER.DBF. It then returns the number of the element stored in row 8, column 2 of the array.
USE customer 
COPY TO ARRAY Name FIELDS customer.cno, customer.company 
ElemNum = AELEMENT(Name,8,2) 
WAIT WINDOW "Row 8, Column 2 = array element " + TRIM(STR(ElemNum,2)) 

AFIELDS()
AFIELDS() places information about the structure of the current table into an array and returns the number of fields in the table. It stores each field name, type, length, and the number of decimal places in numeric fields.
The following example opens CUSTOMER.DBF. A WAIT WINDOW displays the number of fields in CUSTOMER.DBF returned by AFIELDS(). The contents of the array, CUSTOMER, is copied to a file, FLDLIST.TXT, and the file is opened for viewing. Please note that the array name, CUSTOMER, is the same as the table name. 
USE customer 
WAIT WINDOW "Number of fields in CUSTOMER.DBF = " + ; 
 TRIM(STR(AFIELDS(customer),2)) 
DISPLAY MEMORY LIKE customer TO fldlist.txt 
MODIFY FILE fldlist.txt 
AFONT() 
The following example uses the AFONT() function to fill an array with the names of all of the currently available fonts. These will then be displayed.
* Variables: 
* FontArray() is an array that contains information returned from ADIR 
* NumFonts is a numeric variable, containing the number of .DBF's found 
* Index is a numeric, used to specify which element to look at in the 
* FOR loop. 
 
CLEAR 
DIMENSION FontArray(1) && Create an array to hold the font information 
RetVal = AFONT(FontArray) && Use AFONT() to fill the array 
NumFonts = ALEN(FontArray) 
 
IF NumFonts > 0 
 FOR Index = 1 TO NumFonts 
 ? "Font number : "+STR(Index)+" is "+ALLTRIM(FontArray(Index)) 
 ? "This is an example of that font" FONT FontArray(Index),8 
 ENDFOR 
ELSE 
 ? "There were no Fonts Found." 
ENDIF 
ALEN()
ALEN() returns information about the number of elements, rows, or columns in an array. It takes 2 parameters, the name of the array and the return parameter (0 for the number of elements, 1 for the number of rows, and 2 for the number of columns). 
The following example uses ALEN() to return information about CUSTOMER.DBF:
USE customer 
COPY TO ARRAY Name FIELDS customer.cno, customer.company 
@10,10 SAY "Number of elements = " + TRIM(STR(ALEN(Name,0),3)) 
@11,10 SAY "Number of rows = " + TRIM(STR(ALEN(Name,1),3)) 
@12,10 SAY "Number of columns = " + TRIM(STR(ALEN(Name,2),3)) 
ALLTRIM()
This program uses ALLTRIM() to remove all leading and trailing spaces from the variable X. The program will return a browse window with company and the first state being New York.
CLEAR 
SET SAFETY OFF 
SET TALK OFF 
 X = ' ny ' && This is the data your are searching for (space ny space) 
 
USE customer 
INDEX ON STATE TAG state ADDITIVE 
GO TOP 
 
SEEK ALLTRIM(UPPER(X)) 
BROWSE FIELDS COMPANY,STATE 
CLOSE ALL 
SET SAFETY ON 
SET TALK ON 
APPEND 
This example shows how the append command adds a new blank record to the currently selected database. 
USE customer 
APPEND BLANK && Adds new blank record to currently open database 
BROWSE 
This example show how to add a new record the currently selected database. Only the fields listed in the fields parameter will appear in the append window. 
USE customer 
APPEND FIELDS company, contact &&Only fields specified can be edited 
This example shows how to copy the current record to memory variables, add a new blank record and then gather the memory variables into this new record. This can be used to make duplicate copies of one record. 
USE customer 
SCATTER MEMVAR	&&Scatters current record to memory variables 
APPEND BLANK	&&Adds new blank record 
GATHER MEMVAR	&&Gathers the memory variables to new appended record 
BROWSE 
ASCAN() 
The following example creates an array based on the CNO field in CUSTOMER.DBF. It then uses the ASCAN() function to return the number of the array element containing the customer name, "ANTON". If the scan is unsuccessful, ASCAN() will return 0. 
USE customer 
COPY TO ARRAY Name FIELDS customer.cno 
CLEAR 
DISPLAY MEMORY LIKE Name	&& See that "ANTON" is the 3rd element.
CLEAR 
ArVal = ASCAN(Name,"ANTON")	&& Store the element number containing
							&&"ANTON" to the variable ArVal. 
WAIT WINDOW "ANTON is in element " +TRIM(STR(ArVal,1)) + " of the array." 
ASORT() 
ASORT() sorts an array in either ascending or descending order. It will take from 1-3 parameters. 
The following example creates an array using the CNO and COMPANY fields of CUSTOMER.DBF. It then sorts the array first in ascending, then in descending order and displays the results.
·	Parameter 1 = array name 
·	Parameter 2 = element from which sorting starts 
·	Parameter 3 = number of rows in array to sort 
·	Parameter 4 = sort order (0 = ascending, 1 = descending) 

USE customer 
COPY TO ARRAY Name FIELDS customer.cno, customer.company 
=ASORT(Name,1,ALEN(Name,1),0) && Ascending order 
DISPLAY MEMORY LIKE Name 
CLEAR 
=ASORT(Name,1,ALEN(Name,1),1) && Descending order 
DISPLAY MEMORY LIKE Name 
COPY FILE 
The following example copies the file, INVOICES.DBF, to a .DBF with a different name.
COPY FILE invoices.dbf TO invcopy.dbf 
The following example copies the file, INVOICES.DBF, from a specific directory to another explicitly named directory using a fully-specified MS-DOS path.
COPY FILE c:\foxprow\tutorial\invoices.dbf TO a:\invoices.dbf 
COPY STRUCTURE EXTENDED 
The following example copies the structure listing of CUSTOMER.DBF to another table.
USE customer 
COPY STRUCTURE EXTENDED TO custstru	&& Copy structure of CUSTOMER.DBF
									&& to CUSTSTRU.DBF 
USE custstru					&& Open CUSTSTRU.DBF to see the 
BROWSE							&& structure of CUSTOMER.DBF stored 
COPY TAG 
The following example takes the tag ‘cno’ from CUSTOMER.CDX, creates a single-entry index file (.IDX), and then displays the directory listing for the newly-created .IDX file. 
USE customer 
COPY TAG CNO OF customer TO custidx 
DIR custidx.idx 
DDEPOKE() 
The following example uses the RUN/N command to load Microsoft Excel and open a spreadsheet in the ..\sample\dde subdirectory called EXAMPLE.XLS. DDEInitiate() is used to establish a channel between FoxPro for Windows and the open Microsoft Excel spreadsheet. The channel number is stored in a memory variable named "nChanNum".
The DDEPoke() command sends the data values to the spreadsheet cells R1C1 and R1C2. A third DDEPoke() command sends a statistical formula =MEDIAN(numeric1, numeric2,..) to the cell R1C3. Then a DDERequest() command is used to obtain the calculated value in cell R1C3. This calculated value is stored in a memory variable named "cRequest" and the WAIT WINDOW command is used to display the contents of "cRequest". 
RUN/N c:\excel\EXCEL.EXE c:\foxprow\sample\dde\EXAMPLE.XLS 
WAIT " " TIMEOUT 2 && waits for Microsoft Excel to load 
nChanNum=DDEInitiate("Excel","c:\foxprow\sample\dde\example.xls") 
IF nChanNum != -1 
 = DDEPoke(nChanNum, "R1C1", "500") 
 = DDEPoke(nChanNum, "R1C2", "25") 
 = DDEPoke(nChanNum, "R1C3", "=MEDIAN(A1,B1)") 
 cRequest = DDERequest(nChanNum, "R1C3") 
 IF !EMPTY(cRequest) AND DDELastError()=0 
 WAIT WINDOW "The median value is " + cRequest 
 ENDIF 
 = DDETerminate(nChanNum) 
ENDIF 
DECLARE
The following example creates an array using the DECLARE command. Values are stored to the two array elements, and then these values are displayed. 
DECLARE acArray(2)		&& Create the array 
STORE 'A' TO acArray(1)	&& Store a value to element 1 
STORE 'B' TO acArray(2)	&& Store a value to element 2 
DISPLAY MEMORY LIKE acArray	&& Display the contents of the array 
When a one-dimensional array is re-dimensioned to two dimensions, the contents of the original one-dimensional array are copied to the new array in element-to-row order. 
In the following example, a one-dimensional array is converted to a two-dimensional array. The contents of the elements of the one-dimensional array are copied to the first row of the new array, followed by the second row and so on. The additional elements are initialized to false (.F.). 
DECLARE acArrayone(4)	&& Create a one-dimensional array having 4 elements 
STORE 'E' TO acArrayone(1)	&& Store a value to element 1 
STORE 'F' TO acArrayone(2)	&& Store a value to element 2 
STORE 'G' TO acArrayone(3)	&& Store a value to element 3 
STORE 'H' TO acArrayone(4)	&& Store a value to element 4 
DISPLAY MEMORY LIKE acArrayone	&& Display the contents of the array 

DECLARE acArrayone(2,3)	&& Redimension the array to a two-dimensional
							&& array with 3 elements 
DISPLAY MEMORY LIKE acArrayone	&& Display the contents of the array 
In this example, a two-dimensional array is created. Data of different data types is stored to explicit elements of the array. The array elements and the data they contain are then displayed. 
DECLARE aArray(2,3)	&& Create a two-dimensional array with3 elements 
STORE 'Goodbye' TO aArray(1,2)	&& Store a character string to row 1, column 2 
STORE 'Hello' TO aArray(2,2)	&& Store a character string to row 2, column 2 
STORE 99 TO aArray(6)		&& Store a numeric to row 2, column 3 
STORE .T. TO aArray(1)	&& Store a logical to row 1, column 1 
DISPLAY MEMORY LIKE aArray	&& Display the contents of the array. The 
							&& elements which did not have explicit values
							&& stored, default to a logical .F. value.
DEFINE MENU
The following program example shows the building a simple user-defined menu. The menu contains 5 selectable pads. Pads 1 and 2 have popups that are activated when selecting the pad. Upon selecting pads 3, 4 and 5, a single action is performed.
DEFINE MENU mymenu1					&& defines the name of menu 
DEFINE PAD pad1 OF mymenu1 PROMPT 'Pad1'	&& defines pads which will 
DEFINE PAD pad2 OF mymenu1 PROMPT 'Pad2'	&& appear as choices on 
DEFINE PAD pad3 OF mymenu1 PROMPT 'Pad3'	&& menu MYMENU1 
DEFINE PAD pad4 OF mymenu1 PROMPT 'Pad4' DEFINE PAD pad5 OF mymenu1 PROMPT 'Pad5' 
 
DEFINE POPUP popup1 from 1,0	&& defines popups which will 
DEFINE POPUP popup2 from 1,7	&& be activated on selection of 
								&&pads of MYMENU1 
 
DEFINE BAR 1 OF popup1 PROMPT 'Bar1 '	&& defines individual choices 
DEFINE BAR 2 OF popup1 PROMPT 'Bar2'	&& available for each popup 
DEFINE BAR 1 OF popup2 PROMPT 'Bar1 ' 
DEFINE BAR 2 OF popup2 PROMPT 'Bar2' 
 
ON SELECTION PAD pad1 OF mymenu1 ACTIVATE POPUP popup1 && on selection of 
ON SELECTION PAD pad2 OF mymenu1 ACTIVATE POPUP popup2 && pad activates popup 
 
ON SELECTION PAD pad3 of mymenu1 WAIT WINDOW 'Pad3 of Mymemu1' && on selection 
ON SELECTION PAD pad4 of mymenu1 WAIT WINDOW 'Pad4 of Mymemu1' && of pad 
ON SELECTION PAD pad5 of mymenu1 CANCEL 			&& activates action 
 
ON SELECTION BAR 1 OF popup1 WAIT WINDOW 'Bar1 OF Pad1' && on selection of 
ON SELECTION BAR 2 OF popup1 WAIT WINDOW 'Bar2 OF Pad1' && bar initiatss
ON SELECTION BAR 1 OF popup2 WAIT WINDOW 'Bar1 OF Pad2' && action 
ON SELECTION BAR 2 OF popup2 WAIT WINDOW 'Bar2 OF Pad2' 
 
ACTIVATE MENU MYMENU1 && activates the menu 
 
NOTE:     To reset the menu back to the main FoxPro menu after running this example, type the following command in the FoxPro command window: 

SET SYSMENU to DEFAULT 
DEFINE POPUP 
The following example shows the use of DEFINE POPUP with the PROMPT FILES, and PROMPT STRUCTURE clauses, ACTIVATE POPUP, ON SELECTION POPUP, and PROMPT().
PUBLIC cPickDbf, cPickFld 
DEFINE POPUP popdbf; 
 FROM 1,1; 
 MESSAGE 'Please pick a database file'; 
 PROMPT FILES LIKE *.dbf; 
 TITLE 'Pick file' 
 
ON SELECTION POPUP popdbf DO dbfpick 
 
ACTIVATE POPUP popdbf 
IF LASTKEY()=27 
 DEACTIVATE POPUP popdbf 
 RETURN TO MASTER 
ENDIF 
USE (cPickDbf) 
 
DEFINE POPUP popfield; 
 FROM 1,1; 
 TO 10,25; 
 FOOTER 'This is a FOOTER'; 
 MESSAGE 'Please pick a field'; 
 PROMPT STRUCTURE; 
 SCROLL; 
 TITLE 'Pick field' 
 
ON SELECTION POPUP popfield DO fldpick 
ACTIVATE POPUP popfield 
CLOSE DATABASES 
 
PROCEDURE dbfpick 
cPickDbf=PROMPT() 
DEACTIVATE POPUP popdbf 
RETURN 
 
PROCEDURE fldpick 
cPickFld=PROMPT() 
LIST FIELDS &cPickFld 
DEACTIVATE POPUP popfield 
RETURN 
DISPLAY FILES 
The following example uses the DISPLAY FILES command to send a list of .DBF files in the current directory on the named drive to the printer. The PROMPT clause displays a Print dialog. 
DISPLAY FILES ON c: LIKE *.dbf TO PRINTER PROMPT 
The following example uses the DISPLAY FILES command to send a list of .CDX files in the current directory on the named drive to a file called CDXTEST.TXT. It then opens CDXTEST.TXT. 
DISPLAY FILES ON c: LIKE *.cdx TO FILE cdxtest.txt 
MODIFY FILE cdxtest.txt 
DO CASE 
This sample demonstrates a simple DO CASE:
Num = 2 
LogTrue = .T. 
State = "WA" 

? "Before CASE block" 
 
DO CASE 
 CASE State = "CA" && This is FALSE 
 ? "One" 
 CASE State = "WA" .OR. Num = 44 && This is TRUE 
 ? "Two" 
 OTHERWISE && Not executed since a CASE was TRUE 
 ? "Three" 
ENDCASE 
 
? "After CASE block" 
This sample demonstrates a nested DO CASE:
Num = 2 
LogTrue = .T. 
State = "WA" 
 
? "Before CASE block" 
 
DO CASE 
 CASE Num = 98 && This is FALSE 
 ? "One" 
 CASE State = "WA" && This is TRUE 
 ? "Two" 
 DO CASE 
 CASE Num = 83 
 ? "xOne" 
 CASE State = "FL" 
 ? "xTwo" 
 CASE LogTrue 
 ? "xThree" 
 ENDCASE 
 CASE Num = 2 && This is TRUE 
 * This is not executed, even though the condition 
 * is TRUE, since the previous CASE was also TRUE. 
 * Only the first TRUE CASE is executed. 
 ? "Three" 
ENDCASE 
 
? "After CASE block" 
 
* This sample demonstrates the OTHERWISE feature of DO CASE and 
* produces the following output 
* 
* Before CASE block 
* Three 
* After CASE block 
 
Num = 2 
LogTrue = .T. 
State = "WA" 
 
? "Before CASE block" 
 
DO CASE 
 CASE LogTrue = .F. && This is FALSE 
 ? "One" 
 CASE Num = 56 && This is FALSE 
 ? "Two" 
 OTHERWISE 
 * Since all CASE statements were false, this is executed 
 ? "Three" 
ENDCASE 
 
? "After CASE block" 
This program prompts you two enter a two digit state abbreviation. It then returns a brief sentence with information about the input, or returns a message that no information is available for the input. It also converts the state to upper case.
CLEAR 
x = ' ' 
@ 1,1 SAY 'Please type in the two digit state abbreviation ' 
@ 2,2 GET x 
READ 
x = ALLTRIM(UPPER(x)) 
 
DO CASE 
 CASE x = 'AZ' 
 CLEAR 
 ? 'You picked Arizona, a state that is usually hot.' 
 CASE x = 'NY' 
 CLEAR 
 ? 'You picked New York, home of the Big Apple.' 
 CASE x = 'CA' 
 CLEAR 
 ? 'You picked California, where Hollywood is located.' 
 CASE x = 'FL' 
 CLEAR 
 ? 'You picked Florida, the state where all the snowbirds flock to in the 
winter.' 
 OTHERWISE 
 CLEAR 
 ? 'Sorry, you picked a state that we do not have any' 
 ? 'information on or you picked an invalid state.' 
ENDCASE 
RETURN 
This is what the program will do: 
Please type in the two digit state abbreviation 
<Type in ‘ny’ >
Then it will return the following: 
You picked New York, home of the Big Apple 
DO WHILE
In this example, the RECNO() function is used to create a control number for each record in the database. First, the Customer database must be modified to create a numeric field called control. The example moves through the database selects each record, puts the record number in the control field, skips to the next record and performs the operation again, until it hits the end of the file. 
CLOSE ALL 
USE Customer 
GO TOP			&& Make sure you are at the top of the file 
DO WHILE !EOF()	&& Continue until you hit the end of the file 
 REPLACE Customer.control with RECNO() 
 SKIP 			&& Move to the next record 
ENDDO 			&& End the operation 
DTOC() 
The following example converts a date data-type variable to character type data so that the date can be concatenated to the literal string.
@5,10 say "Today is "+ DTOC(DATE()) 
DTOS()
The DTOS() function returns a date in YYYYMMDD format. This date format allows proper year-month-day sort order in indexes. The following example stores a specific date to a memory variable, then displays the DTOS() value of the memory variable. 
m.dDate={03/02/93} 
?DTOS(m.dDate) && Shows 19930302 on desktop 
EVALUATE()
The following example returns the character string from the result of 5 * 4.
? EVALUATE( ‘5*4’ ) && Returns 20 
This example returns the contents of the current record in the contact field of the customer database. 
? EVALUATE(‘Customer.contact’) 
This example returns the character string as a result of the current system date. 
? EVALUATE(‘DATE()’) 
Evaluate() can also be used with variables. The following example stores a date to the Variable dToday then displays the value of dToday as a character expression. 
STORE "DATE()" TO Today 
? EVALUATE(Today) 
FILE()
The following example searches the current directory first and if not found, then follows the search path created by SET PATH. Other drive specifiers and path names can be included with filename. The condition of SET COMPATIBLE has no effect. 
SET DEFAULT TO c:\foxprow\tutorial 
SET PATH TO c:\foxprow\tutorial 
? FILE("foxprow.exe") 
 
 SET PATH TO c:\foxprow 
? FILE("foxprow.exe") 
FLOCK() 
In these examples, the FLOCK function is issued first on an alias name and then on a work area. If it is successful, the IF tests true and returns that status through a wait window and then UNLOCKs the database. If it is unsuccessful, that is also reported through a wait window. Finally, the database is closed. 
USE Customer 
IF FLOCK("CUSTOMER") 
 WAIT WINDOW "File was successfully locked" 
 UNLOCK 
 WAIT WINDOW "File is now unlocked" 
ELSE 
 WAIT WINDOW "File was not locked - Try again later" 
ENDIF 
USE 
WAIT WINDOW "CUSTOMER.DBF is now closed" 

SELECT 2 
USE Details 
IF FLOCK(2) 
 WAIT WINDOW "File was successfully locked" 
 UNLOCK 
 WAIT WINDOW "File is now unlocked" 
ELSE 
 WAIT WINDOW "File was not locked - Try again later" 
ENDIF 
USE 
WAIT WINDOW "DETAILS.DBF is now closed" 
FOPEN() 
This example uses FCREATE() to create a text file, then uses FOPEN() to open the file.
errcre=FCREATE('fopn.txt') 
CLOSE ALL && closes the 'fopn.txt' file 
 
** Now FOPEN() can be used to open the file. 
 
errfile=FOPEN('FOPN.TXT',12) 
 
** The parts of this command are as follows: 
** 
** "errfile" this is a variable, any valid 
** variable name can be assigned to it. 
** It holds the results of the FOPEN() function. 
** Either a valid file handle number, which can 
** be thought of as a number which represents 
** the file that was successfully opened. This 
** variable, holding the file number handle, can 
** be used in other LOW/LEVEL FILE FUNCTIONS to 
** refer to the file opened with the FOPEN(). 
** "errfile" may also hold a -1 which means the 
** file could not be opened. 
 
** "=" Any functions used in FOXPRO must have 
** someway of returning the results. The above 
** example is one way, in which we keep the 
** the results in a variable for later use ** others would be: 
 
=FOPEN('FOPN.TXT',12) 
 
** OR 
 
? FOPEN('FOPN.TXT',12) 
 
** The results of these commands go to the screen 
** or the active window. The results should be 
** a -1 since the file has already been open. 
 
** Note since the file FOPN.TXT was successfully 
** opened with, the first FOPEN() example. 
** errfile holds a positive numeric value. 
 
? errfile 
 
** 'FOPN.TXT' is the first parameter of the 
** FOPEN() function. It must be a character 
** string enclosed in quotes. The path of the 
** file can be included in the quotes. 
 
** ,12) is the second parameter of FOPEN(). It 
** tells FOXPRO how to open the file, READ, WRITE, 
** READ&WRITE, BUFFERED OR UNBUFFERED. The 
** parameter of 12 means READ&WRITE UNBUFFERED. 
 
** Situation where FOPEN() may be useful 
** may include import or append of a 
** particular file type is not feasible, the 
** file could be opened with FOPEN() and 
** the information could read in by LOW/LEVEL 
** functions. 
FSIZE() 
This example of FSIZE() shows the 3 ways that it can be called to display the size of a given field. The first FSIZE command selects the field from the current work area. The second FSIZE command shows the length of the chosen field in a specified work area. The last FSIZE shows the length of the field in the selected database alias. 
USE customer IN 1 
CLEAR 
? "This is the length of the chosen field: " 
?? FSIZE("company") && company is the field that the size 
 && is returned from 
? "This is the length of the chosen field in work area 1: " 
?? FSIZE("company",1) && 1 is the work area where the database 
 && field company is located 
? "This is the length of the chosen field in the selected " 
?? "table/alias: " 
?? FSIZE("company","customer")	&& customer is the databsae alias where
								&& the field company is located.
GATHER 
The following example demonstrates the use of the GATHER MEMVAR command in a data entry screen. Data is first stored to memory variables and when the Save choice is selected, the data is saved. 
SET TALK OFF 
CLEAR 
SELECT 1 
USE customer 
IF _WINDOWS 
 MODIFY WINDOW SCREEN TITLE "Demonstrates the GATHER MEMVAR command" 
FONT "MS SANS SERIF" ,8 
ENDIF 
SCATTER MEMVAR 
Mchoice=SPACE(4) 
@ 1,1 GET M.cno 
@ 3,2 GET M.company 
@ 5,2 GET Mchoice ; 
 PICTURE "@*HN Save;Cancel;Quit" ; 
 VALID myvalid(); 
 STYLE "B" 
READ CYCLE 
CLEAR 
 
IF _WINDOWS 
 MODIFY WINDOW SCREEN 
ENDIF 
RELEASE WINDOW win 
USE 
 
FUNCTION myvalid 
DO CASE 
CASE Mchoice="Save" 
 GATHER MEMVAR FIELD cno, company 
 WAIT WINDOW "Data Saved" +CHR(13)+"CNO "+cno+CHR(13)+"Company "+company
CASE Mchoice="Cancel" 
 SCATTER MEMVAR BLANK 
 WAIT WINDOW "Data not saved" 
CASE Mchoice="Quit" 
 CLEAR READ 
ENDCASE 
SHOW GETS 
This sample demonstrates the use of GATHER FROM an array. An array is first declared and populated, and the data is saved to the table with the GATHER FROM <array> command. 
SET TALK OFF 
CLEAR 
USE CUSTOMER 
DIMENSION Myarray(2) 
Myarray (1)="XXXXX" 
Myarray(2)="Smith" 
WAIT "Before GATHER is executed"+CHR(13)+; 
 "CNO " +cno+CHR(13)+"Company "+company+CHR(13) WINDOW 
GATHER FROM Myarray 
 
WAIT "After GATHER is executed"+chr(13)+"CNO " +cno+CHR(13)+"Company " ;
+company+CHR(13) WINDOW 
IIF() 
The IIF() function returns a value based on whether or not the condition specified in the first parameter is true. If the condition is true, the 2nd parameter is output. If the condition is false, the 3rd parameter is output. 
The following example employs a user-defined function called MYFUNC() to return values from an IIF().
? MYFUNC() 
 
FUNCTION myfunc 
 cState = "WA" 
 bLogTrue = .T. 
 nNum = 25 
 
 * The IIF() function can be used with the IF statement. 
 * The IIF() function can be nested. 
 * In the following statement, IF the value of the nested IIF()s 
 * is 1, a WAIT WINDOW will display. 
 
 IF IIF(IIF(State="WA",LogTrue,.F.),1,2) = 1 
 
 * The IIF() function can be used with many FoxPro commands 
 * Since LogTrue, a logical variable, is True, the text 
 * "True" is returned. 
 
   WAIT WINDOW IIF(LogTrue,"LogTrue = True","LogTrue = False") 
 ENDIF 
 
 * The IIF() function can return the result of a calculation 
 * as illustrated by MAX() 
 * Since LogTrue, a logical variable, is True, the nested 
 * IIF() function is executed. Since Num=1 is false (Num is 
 * equal to 25), the MAX() function is evaluated. The result 
 * of executing the MAX() function is returned, and printed. 
 
 ? IIF(LogTrue,IIF(Num=1,Num+1,MAX(Num,-1)),"False") 
 ? 
 
 * Multiple logical comparisions can be performed in a IIF() function 
 * Since Num=25 is true and State="WA" is true, "Hello" will be 
 * returned to the RETURN statement. 
 
RETURN IIF(Num=25 AND State="WA","Hello","Goodbye") 
MODIFY WINDOW 
The MODIFY WINDOW command allows the changing of attributes of previously designed windows in FoxPro for Windows. The following example shows window test defined and activated with a font of Arial at a point size of 12. After exiting the first read the MODIFY WINDOW changes the font to Foxfont with a point size of 16. The MODIFY WINDOW also changes the location of window test and widens it. Finally, the MODIFY WINDOW command allows the changing of the color for the current window. Upon exiting the second read, the MODIFY WINDOW uses the FILL FILE clause to place a bitmap of puzzle pieces in window test. This bitmap can be found in the \FOXPROW\GOODIES\BITMAPS directory.
USE customer 
DEFINE WINDOW test FROM 1,1 TO 10,50 FONT 'Arial',12 STYLE 'b' 
ACTIVATE WINDOW test 
@ 1,1 SAY 'enter cno ' GET cno SIZE 1,6 
READ 
 
MODIFY WINDOW test FONT 'foxfont',16 STYLE 'i' FROM 5,1 TO 12,70 DOUBLE ; 
 COLOR R/B,R/W* 
CLEAR@ 1,1 SAY 'enter cno ' GET cno SIZE 1,6 
READ 
 
MODIFY WINDOW test FILL FILE 'c:\foxprow\goodies\bitmaps\fox\puzzle.bmp' 
@ 1,1 SAY 'enter cno ' GET cno SIZE 1,6 
READ 
The following command changes the FoxPro desktop location, window size, font attributes and finally changes the title from "Microsoft FoxPro" to "This is the new title for FP4W". 
MODIFY WINDOW SCREEN TITLE "This is the new title for FP4W" ; 
 FROM 5,5 TO 30,80 FONT 'MS Sans Serif',10 
MOVE WINDOW 
The following example will move the window 5 lines down and 2 lines to the right. 
 DEFINE WINDOW mywindow from 1,1 to 10,15 
 ACTIVATE WINDOW mywindow 
 MOVE WINDOW mywindow BY 5,4 
The following example will move the window to the starting position of row 10 and column 20. 
DEFINE WINDOW mywindow from 1,1 to 10,15 
ACTIVATE WINDOW mywindow 
MOVE WINDOW MYWINDOW to 10,20 
OBJNUM()
The following example places two GET objects on the screen and places the cursor in the second GET object
@1,1 GET Word1 DEFAULT "hello" 
@2,1 GET Word2 DEFAULT "world" 
READ WHEN putcursor() 
 
FUNCTION putcursor 
_CUROBJ = OBJNUM(word2) 
ON ERROR 
The following example shows ON ERROR used in conjunction with a procedure. This procedure (Errtest) has been passed the parameters of ERROR(), MESSAGE(),LINENO() and PROGRAM(). These functions will return the error number (ERROR()), the error message(MESSAGE()), the line number(LINENO()) and the program name(PROGRAM()). 
ON ERROR DO Errtest with ERROR(), MESSAGE(), MESSAGE(1),PROGRAM(), LINENO() 
***The next line should cause an error*** 
USE Nodatabase 
ON ERROR && restores the system error handler 

PROCEDURE Errtest 
PARAMETER merr, mess, mess1, mprog, mlineno 
? "Error Number:" + LTRIM(STR(merr)) 
? "Error Message: " + mess 
? "Line of code with error: " + mess1 
? "Line Number with Error: " + LTRIM(STR(mlineno)) 
? "Name of Program with Error: " + mprog 
PROCEDURE 
The following program prompts the user for a name and a birth date. It calls the checknam and checkbd procedures to validate the input, which call the display procedure. 
* Close everything and clear the screen 
CLOSE ALL 
CLEAR ALL 
CLEAR 
SET CENTURY ON 
 
* Get a name and a birthdate 
@ 2,2 SAY "Enter your name: " GET Name ; 
 DEFAULT SPACE(30) ; 
 VALID checknam() 
@ 4,2 SAY "Enter your birthdate: " GET Birthday ; 
 DEFAULT { / / } ; 
 VALID checkbd() 
READ 
 
* This procedure is called from the valid clause for the name object. 
* If the data entered into the name variable is not a full name, the 
* procedure returns 0, which prevents the user from exiting this field 
* until a full name is entered. 
 
PROCEDURE checknam 
IF " " $ ALLTRIM(Name) 
 DO display 
ELSE 
 WAIT WINDOW "Please enter your full name" 
 RETURN 0 
ENDIF 
 
* This procedure is called from the valid clause for the birthday object. 
* If the data entered into the birthday variable is not valid, or if no 
* date was entered, the procedure returns 0, which prevents the user from 
* exiting this field until a full name is entered. 
PROCEDURE checkbd 
DO CASE 
 * Is the date entered greater than today's date? 
 CASE Birthday > DATE() 
 WAIT WINDOW "Who's kidding who? Please try again." 
 RETURN 0 
 * Was no date entered?  CASE EMPTY(Birthday) 
 WAIT WINDOW "Come on. Don't be shy." 
 RETURN 0 
 * Does the data seem valid? 
 OTHERWISE 
 DO display 
ENDCASE 
 
* This procedure is called by the checkname and checkbd procedures to 
* calculate an age based upon the birthdate entered, and to display the 
* results in a sentence. 
PROCEDURE display 
IF LEN(ALLTRIM(Name)) > 0 AND NOT EMPTY(Birthday) 
 @ 6,2 SAY ALLTRIM(PROPER(Name)) + ; 
 " is " + ; 
 LTRIM(STR((DATE()-Birthday)/365.25,5,1)) + ; 
 " years old." 
ENDIF 
RDLEVEL()
After pressing F10, the code sample below will define a window and display a the current read level. As the F10 is sequentially pressed, another window is defined and the read level goes up by one because each window has a READ associated with it which activates the get object on the screen. In this instance, the object is an @GET for each window. If the F10 key is pressed (more than 5 times) so that more than 5 READs are in effect, the error message 'Too many READs in effect.' is displayed because the maximum number of nested READs allowed in FoxPro is 5. This example also allows the READ associated with each screen to be cleared by pressing the terminating Clear Read button (a terminating button clears the current read when pressed). 
** Do not echo information to screen 
SET TALK OFF 
 
** When F10 is pressed, do the procedure addread 
ON KEY LABEL F10 DO addread 
 
** Specify the name of this program file so 
** the program can find the addread procedure 
SET PROCEDURE TO test.prg 
 
** Draw a window 
** Display a read level 
PROCEDURE addread 
X=1 
Y=STR(RDLEVEL()+1) 
 
** If 5 Reads has not been exceeded then define 
** another window 
IF RDLEVEL() <> 5 
 ** Window Name 
 Winname='TEST'+ALLTRIM(STR(RDLEVEL())) 
 
 ** Define and activate window 
 DEFINE WINDOW &cWinname FROM 1,1+5*RDLEVEL() TO 15,60 ; 
 TITLE 'WINDOW #'+ALLTRIM(STR(RDLEVEL()))+' WITH READ' 
 ACTIVATE WINDOW &Winname 
  ** Display current read level and 
 ** draw button to allow read to be terminated 
 @ 1,1 SAY "CURRENT READ LEVEL:" GET Y 
 @ 5,1 GET X ; 
 PICTURE "@*HNT CLEAR READ" ; 
 SIZE 2,15,1 ; 
 DEFAULT 1 
 
 READ CYCLE 
 ** After read is cleared, release window and 
 ** set F10 back to its original macro 
 ** (Disable F10) 
 Winrel= 'TEST'+ALLTRIM(STR(RDLEVEL()+1)) 
 RELEASE WINDOW &Winrel 
 ON KEY LABEL F10 
 
ELSE 
 ** Notify that we cannot have another read disable F10 
 WAIT WINDOW 'ANOTHER READ WILL CAUSE ERROR PRESS ENTER TO CLEAR 
WINDOWS' 
 ON KEY LABEL F10 
ENDIF 
 
RETURN 
REGIONAL 
The following examples create regional / private memory variables and arrays. 
REGIONAL A,B,C	&& Creating regional variables 
A=0				&& Storing 0 to variable A 
B=1				&& Storing 1 to variable B 
C=2				&& Storing 2 to variable C 

#region 0		&& This directive is generated by the screen builder 
REGIONAL D,E,F 

D=3				&& Storing 3 to variable D 
E=4				&& Storing 4 to variable E 
F=5				&& Storing 5 to variable F 

#region 1		&& This directive is generated by the screen builder 
REGIONAL E,F,G 
 
E=4				&& Storing 4 to variable E 
F=5				&& Storing 5 to variable F 
G=6				&& Storing 6 to variable G 

DISPLAY MEMORY LIKE *	&&Display all the variables with their values 

The result from the above code: 
A Priv N 0 ( 0.00000000) reg 
&&Priv indicates a private variable 
B Priv N 1 ( 1.00000000) reg 
&& reg indicates a regional variable 
C Priv N 2 ( 2.00000000) reg 
&& N indicates a numeric variable D Priv N 3 ( 3.00000000) reg 
E Priv N 4 ( 4.00000000) reg 
F Priv N 5 ( 5.00000000) reg 
E________1 Priv N 4 ( 4.00000000) reg &&E and
F are common variable to region 0 
F________1 Priv N 5 ( 5.00000000) reg && and 
region 1. E____1 and F____1 
G Priv N 6 ( 6.00000000) reg 
&& created and common in region 1 
REPLACE
The following example demonstrates how to parse the contents of one field into two separate fields. CUSTOMER.DBF contains a field called CONTACT which contains both first and last names. Using the REPLACE command, it is possible to place the first name into a new field called FIRST and the last name into a new field called LAST. This example assumes that these two new fields have already been added to the database structure. 
USE customer 
 
 REPLACE first WITH SUBSTR(contact,1,AT(' ',contact)-1) 
 REPLACE last WITH SUBSTR(contact,RAT(' ',ALLTRIM(contact))+1) 
To parse the CONTACT field from all the records in the database into the corresponding record's FIRST and LAST fields, issue the following commands with the scope of ALL included: 
REPLACE ALL first WITH SUBSTR(contact,1,AT(' ',contact)-1) 
REPLACE ALL last WITH SUBSTR(contact,RAT(' ',ALLTRIM(contact))+1) 
REPLICATE()
The following program will add a variable length of data for the company field.
USE customer 
DO WHILE !EOF() 
 X=LEN(RTRIM(company)) && company is a field from the customer database file. 
 Y=LEN(company)-x 
 Z=ALLTRIM(company)+REPLICATE(".",y) 
 ? Z 
 SKIP 
ENDDO 
The output from the above code is: 
1st Survey ........... 
1st Data .............. 
Computer Corp .... 
SELECT SQL 
This command retrieves data from tables. The following example creates a read only cursor copy of the Customer database named Query. 
SELECT ALL * FROM Customer 
Clauses used: ALL, FROM. (The default is ALL. Inclusion of this parameter is optional.)
The following example creates a read only cursor copy of unique countries from the Customer database named Query. 
SELECT DISTINCT country FROM Customer 
Clauses used: DISTINCT, FROM.
The following example creates a read only cursor copy of unique countries from the Customer database named Nations with a field name of location. 
SELECT DISTINCT country AS location FROM Customer INTO CURSOR Nations 
Clauses used: DISTINCT, AS, FROM, INTO CURSOR.
The following example creates an array containing the sum of the field from the database into a one dimensional numeric array called Total. 
SELECT SUM(quantity) FROM Details INTO ARRAY Total 
Clauses used: SUM(), FROM, INTO ARRAY 
The following example pulls all the fields from the Details database and displays all the records to the screen without any field headings. 
SELECT * FROM Details TO SCREEN PLAIN 
Clauses used: FROM, TO SCREEN, PLAIN 
The following example creates a text file Test containing all fields and first 50 records from the Customer database without displaying the results to the screen. 
SELECT * FROM CUSTOMER TO FILE Test.txt NOCONSOLE WHERE RECNO() <= 50 
Clauses used: FROM, TO FILE, NOCONSOLE, WHERE 
The following example creates a read only cursor of the first 40 records of the Details database, browses it with a preference name of Alldetail, and releases control of the BROWSE window. 
SELECT * FROM Details PREFERENCE Alldetail NOWAIT WHERE RECNO()<=40 
Clauses used: FROM, PREFERENCE, NOWAIT, WHERE 
The following 2 examples create a read only cursor named Query containing all the records where the country field contains Mexico or Germany. 
SELECT * FROM Customer WHERE country="Mexico" OR Country="Germany" 
Clauses used: FROM, WHERE, OR 
SELECT * FROM Customer ;
 WHERE country="Mexico" ;
UNION ALL ;
 SELECT * FROM Customer ;
WHERE country="Germany" 
Clauses used: FROM, WHERE, UNION, ALL 
SET BRSTATUS 
The following example shows the correct sequence in executing the command and displaying its proper usage. 
SET STATUS BAR OFF 
SET BRSTATUS ON 
USE customer 
BROWSE
SET EXCLUSIVE
Both sets of these commands open the customer database non-exclusively. This then allows more than one user to use the same database at the same time. 
SET EXCLUSIVE OFF
USE customer
or
USE customer SHARE
Both set of these commands open the customer database exclusively. This allows only one user to have the customer database open at a time. 
SET EXCLUSIVE ON
USE customer 
or
USE customer EXCLUSIVE 
SET NOCPTRANS 
Assume we have a table with a memo field called COMMENTS. That memo field contains a Word for Window document. To avoid automatic translation of this field, the following example should be used. 
SET NOCPTRANS TO COMMENTS 
To check for fields that are not to be translated automatically, in the command window type: 
?SET (‘NOCPTRANS’) 
Omitting the CODEPAGE setting in the CONFIG.FPW disallows the automatic translation of character and memo fields. 
SET WINDOW OF MEMO 
The following program example defines a window called test. The next command SET WINDOW OF MEMO tells FoxPro to place the memo field notes into this window when the command MODIFY MEMO is executed. This example uses a database named Employee which contains a memo field named Notes. 
USE employee 
DEFINE WINDOW test FROM 7,10 TO 18,70 
SET WINDOW OF MEMO TO test 
MODIFY MEMO notes 
SHOW GET
This example demonstrates the use of the SHOW GET LEVEL command to refresh a control on another READ level. 
CLEAR 
STORE 1 TO Check 
@ 4,4 GET Check FUNCTION "*C \<Checked" SIZE 1,13 VALID myvalid() 
READ 
 
FUNCTION myvalid 
@ 6,4 SAY "Second READ level" 
Store 0 to Check2 
@ 7,4 GET Check2 FUNCTION "*C \<Unchecked" VALID chgprmpt() 
@ 8,4 GET Done FUNCTION "*HT \<Quit " DEFAULT 1 
 READ 
CLEAR READ ALL 
CLEAR 
 
FUNCTION chgprmpt 
SHOW GET Check,1 PROMPT "Unchked" LEVEL 1 
SKPBAR()
This program defines a popup and sets the skip on BAR 3. The SKPBAR() function is used to test to see if the bar is selectable. SKPBAR() is also used in conjunction with the ON KEY LABEL command to reset the bar so that it can be selected. 
SET TALK OFF 
Test = .T. 
 
ON KEY LABEL F2 Test=!skpbar("cardinfo",3) 
 
DEFINE POPUP cardinfo MARGIN RELATIVE SHADOW COLOR SCHEME 4 
DEFINE BAR 1 OF cardinfo PROMPT '\<View Charges' ; 
 KEY ALT+V, '' 
DEFINE BAR 2 OF cardinfo PROMPT 'View \<Payments' ; 
 KEY ALT+P, '' 
DEFINE BAR 3 OF cardinfo PROMPT 'Vie\<w Users' ; 
 KEY ALT+W, '' SKIP FOR test 
DEFINE BAR 4 OF cardinfo PROMPT '\-' 
DEFINE BAR 5 OF cardinfo PROMPT '\<Charges ' 
DEFINE BAR 6 OF cardinfo PROMPT '\-' 
DEFINE BAR 7 OF cardinfo PROMPT 'E\<xit ' 
 
ON SELECTION POPUP cardinfo; 
 DO choice 
 
ACTIVATE POPUP CARDINFO 
 
PROCEDURE choice 
 
* 
* Demonstrates the SKPBAR() function 
* 
 
WAIT WINDOW IIF(SKPBAR("cardinfo",BAR()),PROMPT() +" is skipped", ; 
 PROMPT() + " is selectable") 
WAIT WINDOW IIF(SKPBAR("cardinfo",3), "Bar 3 is skipped", ; 
 "Bar 3 is selectable") 
* 
* Exits the popup 
* 
 
IF BAR() = 7 
 DEACTIVATE POPUP cardinfo 
ENDIF 
SKPPAD() 
The following example uses SKPPAD() to determine whether the File menu of the System menu is enabled or disabled. 
? SKPPAD('_msysmenu','_mfile') && Returns .F. to signify the File menu is enabled 
 
SET SKIP OF PAD _mfile OF _msysmenu .T. &&disables File menu 
?SKPPAD('_msysmenu','_mfile') && Returns .T. to signify the File menu is disabled 
SOUNDEX()
SOUNDEX() is based on an algorithm invented in the 1920s, and is used by the US Census Bureau. SOUNDEX() is useful to search for data based on the way the word sounds when spoken. The following example creates a search dialog requesting the name of a company. If the name is spelled incorrectly the FindSim procedure looks for the closest sounding match using the SOUNDEX() function. If a match is found, the list and input field is updated to display the closest match. 
The implementation of the SOUNDEX function used by Microsoft FoxPro is character-based as opposed to integer-based. Thus, the following example returns false: 
? SOUNDEX("Kane")=SOUNDEX("Cane") 
While the previous words sound the same when spoken, they begin with different letters. An 'integer' implementation of the SOUNDEX algorithm is available in many texts on computer algorithms and can be coded in Microsoft FoxPro as a replacement for the function provided. 
USE customer && open the table 
INDEX ON SOUNDEX(company) TAG sxComp && index the file 
USE && close the table 

SET TALK OFF 
CLEAR 
USE customer ORDER sxComp AGAIN 

* Define a window for the search dialog 
DEFINE WINDOW getComp FROM 1,1 to 20,60 FLOAT GROW TITLE "SOUNDEX SEARCH" 
ACTIVATE WINDOW getcomp NOSHOW 
 
* Define a popup as the basis for the list 
DEFINE POPUP compPop PROMPT FIELD company SCROLL 
 
List=company && Initialize the list variable as the first element in the list 
 
* Define three interface objects: an input field, a list, and a terminating 
* push button 
@1,2 SAY 'Company:' GET CompName default space(40) valid findsim() 
@3,11 GET List POPUP compPop PICTURE '@&' SIZE 10,40 
@15,25 GET Ok PICTURE '@*T OK' DEFAULT 0 
 
SHOW WINDOW getComp && Display the Search dialog 
 
READ CYCLE 
 
* Cleanup code 
RELEASE WINDOW getcomp 
SET TALK ON 
 
* Find the closest match in the customer database using SOUNDEX() 
 PROCEDURE FindSim IF SEEK(SOUNDEX(Compname)) 
 List=company && update the selected list element 
 Compname=company && update the company input value 
ENDIF 
SHOW GET List 
RETURN 
STR() 
This command returns the character string equivalent to a specified numeric expression. The following examples represent how STR() will handle various values as parameters, and the last example shows how you can use the STR() function to allow a concatenation of a numeric and character expression. 
X=123.456 
? STR(X,7,3) && Displays 123.456 
STR() returns a string of asterisks, indicating numeric overflow if you specify a length less than the number of digits left of the decimal point: 
? STR(X,2,3) && Displays ** 
If you specify fewer decimal places than are in the numeric expression <expN1>, the extra digits are truncated: 
? STR(X,7,2) && Displays 123.46 
STR() pads the character string with leading spaces if you specify a length larger than the number of digits left of the decimal point: 
? STR(X,10,3) && Displays 123.456 

? LEN(STR(X,10,4)) && Displays 10
Example using the STR() function to concatenate a numeric value with character string: 
X=1 
? STR(X)+"ABC" && Displays 1ABC 
1ABC 
STRTRAN() 
This command uses the following memory variables : m.fld, m.search, m.var which contain the character expression to be searched for. The example uses the STRTRAN() function to update a character expression or memo field for occurrences of a second character expression or memo field, and replaces each occurrence with a third character expression or memo field. 
* 
* Program Example :STRTRAN() function used to convert a three letters in * field to from "OLD" to "NEW" resulting in a new string value of NEW123 
* 
STORE "OLD123" to m.fld && store value to cM.fld 
?STRTRAN(m.fld,"OLD","NEW") && display the converted value NEW123 
* Now update the second letter in NEW from "E" to "O" resulting in the 
* combined string value of NOW123. 
* 
?STRTRAN(m.fld,"E","O",2,1) && display the converted value NOW123 
* 
* This program example of the :STRTRAN() function is used to convert a 
* memory varitable string found in the title field of the customer file 
* from "Representive" to "Associate" resulting in a new string value of 
* "Sales Associate" in the title field of the Customer database. 
* 
STORE 'Sales Representive' TO m.search 
CLOSE DATABASES 
USE customer 
WAIT WINDOW 'Display Company,Title, and Contact' NOWAIT 
BROWSE FIELDS Company,Title,Contact TimeOut 10 
WAIT WINDOW 'Replace first occurance of "Representive" in TITLE field with 
Associate' 
NOWAIT 
REPLACE Title WITH STRTRAN(m.search, 'Representative', 'Associate') 
WAIT WINDOW 'The title field now contains "Associate" instead of Representive' 
NOWAIT 
BROWSE FIELDS Company,Title,Contact TIMEOUT 10 
* 
* In this example a memory variable string found in the title 
* field of the customer file called "Owner" is updated with "Corporate, CEO" resulting in a new 
* string value of "Corporate, CEO" in the title field of the Customer database. 
* 
m.var = "Owner" 
WAIT WINDOW 'Replace first occurance of "Owner" in TITLE field with Corporate, CEO' 
NOWAIT 
REPLACE Title WITH STRTRAN(m.var, 'Owner', 'Corporate, CEO') 
BROWSE FIELDS Company,Title,Contact TimeOut 10 
WAIT CLEAR 
STUFF() 
The following example converts a character string to a date format. 
W="07261993" X="/" 
Y=STUFF(cW,3,0,X) 
Z=STUFF(cY,6,0,X) 
? CTOD(Z) 
SUBSTR() 
This example takes a character string and converts it into a readable date format. 
X="07261993" 
Y=SUBSTR(X,1,2)+"/"+SUBSTR(X,3,2)+"/"+SUBSTR(X,5,4) 
? CTOD(Y) 
SYS(1001) 
The values shown in these examples may differ greatly when compared to the values returned on your own system. 
? SYS(1001) && Displays 1310688 
To return the amount of memory available for user-defined objects, use the value of SYS(1016) subtracted from the value of SYS(1001): 
? VAL( SYS(1001) ) - VAL( SYS(1016) ) && Displays 1210400.00 
SYS(1016) 
The values shown in these examples may differ greatly when compared to the values returned on your system. 
? SYS(1016) && Displays 100256 
To return the amount of memory available for user-defined objects, use the value of SYS(1016) subtracted from the value of SYS(1001): 
? VAL( SYS(1001) ) - VAL( SYS(1016) ) && Displays 1210400.00 
SYS(2011) 
This example shows the result of using SYS(2011) at record number 12. 
USE Customer 
GOTO 12 
? SYS(2011) && Displays Record Unlocked 
SYSMETRIC() 
The following examples print out the size of the specified display element: 
? SYSMETRIC(2) && Windows screen height 
? SYSMETRIC(9) && Height of window title 
? SYSMETRIC(29) && Window controls height 
? SYSMETRIC(19) && Maximum cursor height 
TRANSFORM() 
The following example uses the TRANSFORM() to format a phone number field. 
Phone='123333333' 
? TRANSFORM(Phone, "@R (999) 999-9999") && Displays (123) 333-3333 
VAL()
The VAL() function converts character numbers to actual numeric values. A character number can be represented by:
	char_num='10' 
? TYPE('char_num') && Returns a "C" - character 
The variable CHAR_NUM looks like a number but it is holding the number as a character because of the quotes. 
To store an actual numeric value to a variable do not use quotes. 
Num_num=10 
? TYPE('num_num') && Returns a "N" - numeric 
At this point, it is not possible to add these two variables, cChar_num and nNum_num, together. 
? Char_num+Num_num && This line will error out. 
The above command results in an error, "OPERATOR/OPERAND TYPE MISMATCH," this is where the VAL() function can be helpful. The example below executes without error. 
? VAL(Char_num)+Num_num 
Other situations where the VAL() function would be useful are Index expressions, Report expression, and any of the Numeric functions. Especially where there is concatenation of Numeric and Character field types. 
VARREAD() 
This function returns in upper-case the name of the memory variable, array element or field used to create the current @ ... GET field or control. Controls include check boxes; fields; invisible, push or radio buttons; lists; popups; spinners; and text editing regions. 
If a Browse, Change or Edit window is active, the name of the current field is returned with the first letter of the field name capitalized. 
VARREAD() is identical to SYS(18). Both can be used to pass the current field or control name to a procedure that in turn can provide context-sensitive help, as in the following example. 
SET TALK OFF 
CLOSE DATABASES 
ON KEY LABEL F1 DO Help WITH VARREAD() 
USE customer 
SCATTER TO temp 
DEFINE WINDOW input FROM 6,10 to 18,70 PANEL 
ACTIVATE WINDOW input 
@ 1,3 SAY 'Customer: ' GET company 
@ 3,3 SAY 'Address: ' GET address 
@ 5,3 SAY 'City: ' GET city 
@ 7,3 SAY 'State: ' GET state 
@ 7,18 SAY 'Zip: ' GET zip 
@ 9,7 SAY 'Press <Escape> to cancel or <F1> for help' 
READ 
GATHER FROM temp 
DEACTIVATE WINDOW input 
RELEASE WINDOW input 
ON KEY LABEL F1 
RETURN 

*** Help Procedure *** 
 
PROCEDURE Help 
PARAMETERS fieldname 
DO CASE 
 CASE fieldname = 'COMPANY' 
 WAIT WINDOW 'Enter the company name' NOWAIT 
 CASE fieldname = 'ADDRESS' 
 WAIT WINDOW 'Enter the street address' NOWAIT 
 CASE fieldname = 'CITY' 
 WAIT WINDOW 'Enter the city name' NOWAIT 
 CASE fieldname = 'STATE' 
 WAIT WINDOW 'Enter a two character state abbreviation' NOWAIT 
 CASE fieldname = 'ZIP' 
 WAIT WINDOW 'Enter the five digit Zip code' NOWAIT 
ENDCASE 
RETURN 
In the above example, pressing the F1 key while in the ADDRESS field, for instance, does the following: 
1.	The procedure Help is called immediately, suspending the READ. 
2.	The value of VARREAD() is passed into the procedure. 
3.	The variable 'fieldname' takes on the value of 'ADDRESS'. 
4.	The CASE conditions are compared, and a match is found on the second one. 
5.	The message "Enter the street address" is displayed in the WAIT window. 
6.	Program control returns and falls through the remaining CASE statements. 
7.	The Help procedure is exited, returning control to the READ. 
The following example uses the WAIT window to display the name of the current field and its contents while in a BROWSE: 
SET TALK OFF 
CLOSE DATABASES 
ON KEY LABEL F12 WAIT WINDOW VARREAD()+': '+typix(VARREAD()) NOWAIT 
USE customer 
BROWSE 
 
FUNCTION typix 
PARAMETER fld 
 
Kind=TYPE(fld) 
 
RETURN IIF(kind='C', ALLTRIM(EVALUATE(fld)), ; 
 IIF(kind='N', ALLTRIM(STR(EVALUATE(fld))), ; 
 IIF(kind='D', DTOC(EVALUATE(fld)), ; 
 IIF(kind='L', IIF( EVALUATE(fld )=.T., 'True', 'False'), ; 
 IIF(kind='M',"Memo","General"))))) 
In the above example, pressing the F12 key causes the following: 
1.	The current field name is passed to the user-defined function, 'typix'. 
2.	The variable 'fld' is assigned the value of the current field name. 
3.	The variable 'kind' is given the field's data type by the TYPE() function. 
4.	The nested in-line IF evaluates the 'kind' variable for a match. 
5.	The matching string equivalent is returned for the appropriate data type. 
6.	The WAIT window displays the current field name and contents (excepting Memo and General fields that show instead "Memo" and "General" respectively.) 
WOUTPUT()
This example will use the optional <window name> parameter of the WOUTPUT() function. When this parameter is used, the WOUTPUT() function will return either .T. or .F. First a window called "test" will be defined. Next the window named "test" will be activated. This will make "test" the current output window. Finally the result of the WOUTPUT(<window name>) function will be displayed in the window named "test" by using the ? to output the logical value that is returned. This logical value should be .T. This example should be run from a program file. The window can be cleared off of the desktop afterwards by issuing the CLEAR WINDOWS command from the command window. 
DEFINE WINDOW test FROM 1,1 TO 5,5 
ACTIVATE WINDOW test 
WAIT WINDOW 'The window "test" has just been activated' 
WAIT WINDOW 'WOUTPUT() will be issued next' 
? WOUTPUT('test') 
_CUROBJ 
_Curobj is a global numeric system variable. The following example demonstrates how _Curobj can be used to change the current object on a screen. The screen below contains 3 @GET fields. When the F2 key is pressed, the cursor will jump to the second @GET object (@ 3,1 GET y). The code in the PROCEDURE moveto could be put in a VALID or WHEN clause also. In order for this example to work properly, the SHOW GETS command must be present. 
CLEAR 
ON KEY LABEL F2 DO moveto && Reassign the F2 key 
@1,1 GET X DEFAULT SPACE(10) && x can be any variable or database field 
@2,1 GET Y DEFAULT SPACE(5) && y can be any variable or database field 
@3,1 GET Z DEFAULT SPACE(5) && z can be any variable or database field 
READ CYCLE 
 
ON KEY LABEL F2 && Reset the F2 key 
 
PROCEDURE moveto 
_CUROBJ=2 && Set _Curobj to the second object 
SHOW GETS && If line not present the example will NOT work 
RETURN .T. 
Additional Information
Additional information concerning the use of FoxPro commands and functions can be found by looking at the following articles:

Q94345	Q99910	Q100430	
Q95698	Q96360	Q97638	
Q103645	Q98691	Q105836	
Q99904	Q98959	Q99595	
Q104670	Q105003	Q103696	
Q103645	Q102787	Q104325