SET DEFAULT Command •Function: Specifies the default drive and directory. •Syntax: SET DEFAULT TO [cPath] Parameters cPath. Specifies one of the following: •A drive designator •A drive designator with a directory name •A child directory name •Any of the above using Microsoft MS-DOS shorthand notation ( \ or ..) Remarks •SET DEFAULT changes the default directory to the directory you specify. •Microsoft® Visual FoxPro® searches for a file in the default Visual FoxPro directory. The default directory is the one from which you start Visual FoxPro. However, you can specify a different default directory in your Visual FoxPro configuration file or in a startup program. Remarks… •If Visual FoxPro cannot find a file in the default directory, it then searches the Visual FoxPro path if one has been specified. Use SET PATH to specify the Visual FoxPro path. •If you create a file and do not specify where to place it, the file is placed in the default Visual FoxPro directory. Remarks… •The SET DEFAULT command is not supported in either single or multithreaded DLL servers. This command changes the default directory of the entire process, so all threads which are part of the process are affected. Use the SET PATH command in DLL servers, in place of CD and CHDIR. Tips •SYS(5) returns the default drive. •SYS(2003) returns the default directory with no drive designator. •SYS(5) + SYS(2003) returns the default drive and the directory. Examples Set Default to D && Changes default drive to D Set Default to D: && Changes default drive to D Set Default to D:\Bruno\Exercises Set Default to D:\Bruno && Specifies a specific directory Set Default to Exercises && Changes the default directory to D:\Exercises if the root directory on drive D is the default directory of Visual Foxpro. Note: && indicates the start of an inline comment. Examples… Set Default to \ && Makes the root directory the default directory – that is, if the current directory is other than the root directory (e.g., D:\Bruno\Exercises) Set Default to .. && Moves the default directory one level (up) towards the root directory. CREATE Command •Function: Opens the Table Designer so you can create a Visual FoxPro table. •Syntax: Create [filename│?] Parameters [ FileName| ?] Specifies the name of the table to create or opens the Create dialog box so you can browse for a location to save the table and specify the name of the table to create. • If FileName is specified, it opens the Table Designer so you could define the fields and their attributes in the table. • If ? is used, it opens the Create dialog box so you can browse for a location to save the table and specify the name of the table to create. Remarks •If a database is open when you create a table, the table is added automatically to the database. •When running on the Windows operating system, you cannot create a table with the name of an MSDOS device, such as CON, NUL, PRN, and COM1. Avoid using hyphens in a table name because hyphenated table names do not appear in the Data Session window and can cause confusion with the alias pointer (->). Remarks… •After opening the Table Designer, you need to define attributes for the fields in the table. After you create the table structure, you can add records to the table. For more information, see Creating Tables. •The SQL CREATETABLE command makes it possible to specify fields and their attributes programmatically. For more information, see CREATE TABLE - SQL Command. Examples Set Default to F:\Bruno Create Students Set Default to D:\Bruno Create ? APPEND Command •Function: Adds one or more new records to the end of a table. •Syntax: APPEND [BLANK] [IN nWorkArea | cTableAlias] [NOMENU] Parameters BLANK adds one blank record to the end of the current table. Visual FoxPro does not open an editing window when you issue APPEND BLANK. You can edit the new record with BROWSE, CHANGE, or EDIT. IN nWorkArea specifies the work area of the table to which a new record is appended. Parameters… IN cTableAlias specifies the alias of the table to which a new record is appended. If you omit nWorkArea and cTableAlias, a new record is appended to the table in the currently selected work area. If you issue APPEND, a blank record is added to the table you specify with nWorkArea or cTableAlias and the table is automatically selected. If you issue APPEND BLANK, a blank record is added to the table you specify with nWorkArea or cTableAlias and the table is not selected. Parameters… NOMENU specifies that the Table menu title is removed from the system menu bar, preventing changes to the format of the editing window. DELETE Command •Function: Marks records for deletion. •Syntax: DELETE [Scope] [FOR lExpression1] [WHILE lExpression2] [IN nWorkArea | cTableAlias] [NOOPTIMIZE] Parameters Scope. Specifies a range of records to mark for deletion. The default scope for DELETE is the current record (NEXT 1). The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST. For more information on scope clauses, see Scope Clauses. Parameters… FOR lExpression1. Specifies a condition whereby only the records that satisfy the logical condition lExpression1 are marked for deletion. Rushmore Query Optimization optimizes a query created with DELETE ... FOR if lExpression1 is an optimizable expression and the table is indexed on DELETED( ). For best performance, use an optimizable expression in the FOR clause. For information on Rushmore optimizable expressions, see SET OPTIMIZE, and Using Rushmore Query Optimization to Speed Data Access in Optimizing Applications. Parameters… WHILE lExpression2. Specifies a condition whereby records are marked for deletion for as long as lExpression2 evaluates to true (.T.). IN nWorkArea. Specifies the work area of the table in which records are marked for deletion. Parameters… IN cTableAlias. Specifies the alias of the table in which records are marked for deletion. If you omit nWorkArea and cTableAlias, records are marked for deletion in the table in the currently selected work area. NOOPTIMIZE. Disables Rushmore optimization of DELETE. Remarks •Records marked for deletion aren't physically removed from the table until PACK is issued. Records marked for deletion can be recalled (unmarked) with RECALL. Example The following example opens the Customer table in the TestData database. DELETE is used to mark all records for deletion where the Country field contains USA. All the records marked for deletion are displayed. RECALL ALL is used to unmark all records marked for deletion. Example… CLOSE DATABASES OPEN DATABASE (HOME(2) + 'Data\testdata') USE customer && Opens Customer table DELETE FOR country = 'USA' && Marks for deletion CLEAR LIST FIELDS company, country FOR DELETED( ) && Lists marked records RECALL ALL && Unmark all records marked for deletion. SET PATH Command •Function: Specifies a path for file searches. •Syntax: SET PATH TO [Path] [ADDITIVE] Parameters TO [Path] specifies the directories you want Visual FoxPro to search. Use commas or semicolons to separate the directories. [ADDITIVE] appends additional paths to the end of the current path. Note •Visual FoxPro will not recognize a path name properly if a disk or directory name contains an exclamation point (!) •On all FoxPro platforms, functions that return path information, such as CURDIR( ), DBF( ), and SYS(2003), use Microsoft MS-DOS path-naming conventions in their return values. Remarks • Issue SET PATH TO without Path to restore the path to the default directory. Use SET DEFAULT to specify the default directory and CURDIR( ) to return the current default directory. • SET PATH is not scoped to the current data session; changes you make to the default path using the SET PATH command affect all data sessions. • SET PATH is limited to a maximum of 4095 characters. • When using the ADDITIVE parameter, paths must be included either as a quoted string or valid expression. Examples ff = [“Bruno3"] SET PATH TO &ff ADDITIVE ** or ** ff = “Bruno3“ SET PATH TO '&ff' ADDITIVE Note: * indicates the start of a line comment. Go │ Goto Command • Function: Moves the record pointer to the specified record number. • Syntaxes: • GO [RECORD] nRecordNumber [IN nWorkArea | IN cTableAlias] • GO TOP | BOTTOM [IN nWorkArea | IN cTableAlias] • GOTO [RECORD] nRecordNumber [IN nWorkArea | IN cTableAlias] • GOTO TOP | BOTTOM [IN nWorkArea | IN cTableAlias] Parameters •RECORD nRecordNumber. Specifies the physical record number to move the record pointer to. You can omit GO or GOTO entirely and specify just the record number. If you specify just the record number, you can move the record pointer only within the current work area. •IN nWorkArea. Specifies the work area of the table in which the record pointer is moved. Parameters … •IN cTableAlias. Specifies the alias of the table in which the record pointer is moved. •TOP. Positions the record pointer on the first record in the table. If the table has an ascending index in use, the first record is the record with the lowest key value. If the index is in descending order, the first record is the record with the highest key value. Parameters … •BOTTOM. Positions the record pointer on the last record in the table. If the table has an ascending index in use, the last record is the record with the highest key value. If the index is in descending order, the last record is the record with the lowest key value. Remarks •GO and GOTO can be used interchangeably. These commands operate on the table in the current work area unless you specify another work area with the IN clause. Example CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE products && Opens Products table USE customer IN 0 && Opens Customer table GO BOTTOM IN products CLEAR ? RECNO('products') GO TOP ? RECNO( ) && Displays 1 GO 5 ? RECNO( ) && Displays 5 ? │ ?? Command • Function: Evaluates expressions and sends the results to the main Visual FoxPro window, an active user-defined window, or the printer. • Syntax: •? | ?? Expression1 [PICTURE cFormatCodes] | [FUNCTION cFormatCodes] | [VnWidth] [AT nColumn] [FONT cFontName [, nFontSize [, nFontCharSet]] [STYLE cFontStyle | Expression2]] [, Expression3] … Parameters •? Expression1. Evaluates the expression specified by Expression1 and sends a carriage return and line feed preceding the expression results. The results display on the next line of the main Visual FoxPro window or the active user-defined window and are printed at the left margin of a page unless a function code specified by cFormatCodes or the _ALIGNMENT system variable specifies otherwise. Parameters… If you omit the expressions, a blank line is displayed or printed. A space is placed between expression results when multiple expressions are included. If Expression1 is an object, the ? command returns the character string, "(Object)". Parameters… •?? Expression1. Evaluates the expression specified by Expression1 and displays the expression results on the current line at the current position of the main Visual FoxPro window, an active user-defined window, or the printer. A carriage return and line feed are not sent before the results. Parameters… •PICTURE cFormatCodes. Specifies a picture format in which the result of Expression1 is displayed. cFormatCodes can consist of function codes, picture codes, or a combination of both. You can use the same codes available in the Format Property and InputMask Property. Function codes affect the overall format of the result; picture codes act on individual characters in the result. Parameters… If function codes are used in cFormatCodes, they must appear before the picture codes and they must be preceded by an at (@) sign. Multiple function codes with no embedded spaces can immediately follow the @ sign. The last function code must be followed by one or more spaces. The space or spaces signal the end of the function codes and the start of the picture codes. Parameters… •FUNCTION cFormatCodes. Specifies a function code to include in the output from the ? and ?? commands. If the function clause is included, do not precede the function codes with an @ sign. Function codes must be preceded by a @ sign when included in PICTURE. Parameters… •V nWidth. Specifies a special function code that enables the results of a character expression to stretch vertically within a limited number of columns. nWidth specifies the number of columns in the output. ? 'This is an example of how the V function code works.' ; FUNCTION 'V10' Parameters… •AT nColumn. Specifies the column number where the output is displayed. This option makes it possible for you to align output in columns to create a table. The numeric expression nColumn can be a user-defined function that returns a numeric value. Parameters… •FONT cFontName[, nFontSize [, nFontCharSet]]. Specifies a font for output by the ? or ?? command. cFontName specifies the name of the font, and nFontSize specifies the point size. You can specify a language script with nFontCharSet. See the GETFONT( ) Function for a list of available language script values. For example, the following command displays the system date in 16-point Courier font: Parameters… •FONT cFontName[, nFontSize [, nFontCharSet]]. Specifies a font for output by the ? or ?? command. cFontName specifies the name of the font, and nFontSize specifies the point size. You can specify a language script with nFontCharSet. See the GETFONT( ) Function for a list of available language script values. For example, the following command displays the system date in 16-point Courier font: • ? DATE( ) FONT 'Courier',16 Parameters… If you include the FONT clause but omit the point size nFontSize, a 10-point font is used. If you omit the FONT clause, and output for the ? or ?? command is placed in the main Visual FoxPro window, the main Visual FoxPro window font is used for the output. If you omit the FONT clause, and output for the ? or ?? command is placed in a user-defined window, the user-defined window font is used for the output. Note: If the font you specify is not available, a font with similar font characteristics is substituted. ??? Command •Function: Sends output directly to the printer. •Syntax: •??? cExpression Parameters •cExpression. Specifies the characters that are sent to the printer. Remarks • A group of three question marks bypasses the printer driver and sends the contents of cExpression directly to the printer. cExpression must contain valid printer codes. • Printer control codes make it possible for you to reset the printer, change type styles and sizes, and enable or disable boldface printing. These codes can consist of any combination of printable or nonprintable characters that are specific to the printer you are using. You can direct control codes to the printer in several different ways: • Use combinations of CHR( ) and quoted strings concatenated with + to send ASCII characters directly to the printer. Remarks… • Tables store data in a row and column format, similar to a spreadsheet. Each row represents a record, and each column represents the fields in each record. Tables in Visual FoxPro can exist as a free table or as a database table. • A free table is a table (.dbf) file that is not associated with any database. A database table is a table file that is associated with a database. Database tables can have properties that free tables do not have, such as field-level and record-level rules, triggers, and persistent relationships. Format Property • Function: Specifies the input and output formatting of a control's Value property. Available at design time and run time. • Syntax: Control.Format[ = cFunction] Return Value •cFunction. Specifies the character constraints for data entry and formatting for display. The following table lists the valid cFunction values for the appropriate controls. cFunction EditBox control K Description Selects all the text when the control gets focus. cFunction Description Spinner control $ Displays the currency symbol. ^ Displays numeric data using scientific notation. K Selects all the text when the control gets the focus. L Displays leading zeros instead of spaces in the text box. cFunction Description Spinner control… R Displays the format mask for the text box that is specified in the InputMask property. The mask formats data for easier entry and clearer display (for example, if the mask is 99999, the number 12345 is displayed as 12-345), but is not stored as part of the data. Use only with character or numeric data. cFunction Description TextBox control and Column object ! $ ^ Converts alphabetic characters to uppercase. Use with data of Character type only. Displays the currency symbol. The ControlSource property must specify a numeric source for the text box. Displays numeric data using scientific notation. The ControlSource property must specify a numeric source for the text box. cFunction Description TextBox control and Column object … A D E F Allows alphabetic characters only with no spaces or punctuation marks. Uses the current SET DATE format. Edits Date values as British dates. Prevents Varchar values from being padded with trailing spaces in text boxes or Varbinary values from being padded with trailing zeroes (0s). Notes • For text boxes bound to data with Varchar type, the MaxLength property must be set to a nonzero value to permit input for the desired number of characters. • When you drag a field with Varchar type to a form, the created text box's Format property is set to "F", and the MaxLength property is set to the maximum length for the Varchar field. When you drag a Grid control to a form and create TextBox controls for columns with Varchar type, the Format property is set to "F", and the MaxLength property is set to the maximum length for the Varchar field. Notes • When you drag a field with Varbinary type to a form or when you drag a Grid control to a form and create TextBox controls for columns with Varbinary type, the following occur: Format property is set to "F". MaxLength property is set to the maximum length multiplied by 2 for the Varchar field. InputMask property is filled with "H" up to the value of the MaxLength property. cFunction Description TextBox control and Column object … K Selects all the text when the control gets the focus. L Displays leading zeros instead of spaces in the text box. The ControlSource property must specify a numeric source for the text box. M Included for backward compatibility. cFunction Description TextBox control and Column object … R T YS YL Displays the format mask for the text box that is specified in the InputMask property. The mask formats data for easier entry and clearer display. For example, if the mask is 99-999, the number 12345 is displayed as 12-345 but is not stored as part of the data. Use only with Character or Numeric data. Trims leading and trailing blanks from the input field. Displays Date values in a short date format determined by the Windows Control Panel short date setting. Displays Date values in a long date format determined by the Windows Control Panel long date setting. cFunction Description EditBox control, TextBox control, Column object, and Spinner control Z Displays the value as blank if it is 0, except when the control has focus. Dates are also supported in these controls. The / / date delimiters are not displayed unless the control has focus. Remarks • Applies To: Column | ComboBox | EditBox | Spinner | TextBox • The Format property specifies a behavior for the entire input field. You can mix several Format codes, but they always affect everything in the input field. This property contrasts to the InputMask property in which each entry in the input mask corresponds to an entry in the input field. • The Format property mimics the behavior of the FUNCTION clause in the @ ... GET and @ ... EDIT commands Table Creation • Tables store data in a row and column format, similar to a spreadsheet. Each row represents a record, and each column represents the fields in each record. Tables in Visual FoxPro can exist as a free table or as a database table. • A free table is a table (.dbf) file that is not associated with any database. A database table is a table file that is associated with a database. Database tables can have properties that free tables do not have, such as field-level and record-level rules, triggers, and persistent relationships. Table Creation… • The following list includes some of the benefits database tables offer: Long names for the table and for each field in the table. Captions and comments for each table field. Default values, input masks, and format for table fields. Default control class for table fields. Field-level and record-level rules. Primary key indexes and table relationships to support referential integrity rules. One trigger for each INSERT, UPDATE, or DELETE event. Table Creation… • However, free tables are useful for storing information outside of a database. For example, for example, you can use free tables to store lookup information that multiple databases share. For more information about the benefits of associating tables with a database, see Databases in Visual FoxPro. • To view a sample table, open one of the table (.dbf) files for the Northwind database located in the Visual FoxPro ...\Samples\Northwind directory. For more information, see How to: View Records in Tables. Considerations for Table Creation • When creating tables, remember the following considerations: Make sure field's data type matches the type of information you want to store. Make sure the field is wide enough to accommodate the information it stores and displays. Set an appropriate number of decimal places for Numeric or Float fields. Make sure that fields that can accept null values are configured to accept them. How to: View Records in Tables •You can view the records in a table by opening it in a browse window. A browse window displays data in a table as rows (records) and columns (fields) that you can scroll through. For more information, see Browse Window. To browse data in a free table 1. 2. On the File menu, click Open. In the Open dialog box, browse to the location of the table you want to view. 3. In the Files of type box, select the Table (*.dbf) file type to display only table files. 4. Select the table file you want to view. 5. On the View menu, click Browse. The table you selected opens in a browse window. To browse data in a database table 1. Open the database in the Database Designer. 2. Select the table you want. 3. On the Database menu, click Browse. The table opens in a browse window. To browse data in a table from a project 1. Open the project in the Project Manager. 2. Expand the Data node and choose one of the following: • To browse a database table, expand the Databases node, then the Tables node. -OR• To browse a free table, expand the Free Tables node. 3. Click the table you want to view, and then Browse. The table you selected opens in a browse window. To browse a table programmatically 1. Open the table with the USE command. 2. Follow USE with the BROWSE command. Tip: To prevent users from adding records to a table while browsing a table, include the NOAPPEND clause in the BROWSE command.