Remarks

A Browse window allows you to view records in a table, edit those records, and append additional records. Visual FoxPro allows you to have several Browse windows open at the same time.

If you press ESC to exit a Browse window, changes made to the last field you modified are discarded. However, if you move to another record after modifying a field, your changes to the field are saved.

The field list can specify any combination of fields or calculated fields. The syntax of the field list is:

FieldName1 [:R] [:nColumnWidth] [:V = lExpression1 [:F] [:E = cMessageText]] [:P = cFormatCodes] [:B = eLowerBound, eUpperBound [:F]] [:H = cHeadingText] [:W = lExpression2] [, FieldName2 [:R]. ]

Calculated Fields The field list can contain statements for creating calculated fields. A calculated field contains read-only data created with an expression. The expression can take any form, but it must be a valid Visual FoxPro expression.

The format of the statement you use to create a calculated field is:

The following example creates a calculated field called location :

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE customer && Open customer table BROWSE FIELDS location = ALLTRIM(city) + ', ' + country

city and country are the names of fields from the currently selected table.

The FIELDS clause field list includes options that enable special handling of fields displayed in a Browse window:

Specifies that the field is read-only. The data it contains can be viewed but not edited.

In the following example, a Browse window is opened with the cust_id and company fields. The cust_id field is read-only and cannot be changed.

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE customer && Open customer table BROWSE FIELDS cust_id:R, company
: nColumnWidth

Specifies the display size for a field in columns. The value of : nColumnWidth doesn't affect the size of the field in the table; it only alters the way the field appears in the Browse window.

:V = lExpression1 [:F] [:E = cMessageText ]

Lets you perform field-level data validation within the Browse window. If lExpression1 evaluates to true (.T.) when you move the cursor from a field, the data input into the field is considered correct and the cursor moves to the next field.

If lExpression1 evaluates to false (.F.), the data input is considered incorrect, the cursor remains in the field and an error or exception is raised. If lExpression1 evaluates to 0, the data input is considered incorrect and the cursor remains in the field but no error message appears.

The verify option is not executed for memo fields.

By default, lExpression1 is evaluated only when the field is modified. To force verification, include the :F option.

You can display your own error message by including the :E option described below.

Determines whether the expression in the verify option is evaluated when you move the cursor out of a field or another window is activated. If :F is not included, lExpression1 is evaluated only if changes are made to the field. If :F is included, lExpression1 is evaluated even if the field isn't modified.

If the validation expression :V = lExpression1 evaluates to true (.T), the cursor leaves the field normally. If the expression evaluates to false (.F.), the cursor remains in the field, and Visual FoxPro generates an error message.

If the error option (:E) is included, cMessageText appears instead of the system error message. cMessageText appears only if SET NOTIFY is ON. The bell is sounded if SET BELL is ON.

If :V = lExpression1 evaluates to 0, no message appears and the cursor remains in the field being validated. This option lets you display your own error messages in validation routines.

The following example opens the products table and displays the product_id and prod_name fields. The product_id field is a numeric field that will accept up to five numbers. For purposes of this example, we consider a product_id greater than 100 to be invalid.

:V specifies the validation criteria. :F forces the validation check to be performed whether the data is changed or not. :E replaces the Visual FoxPro system error message with a user-defined error message. In Visual FoxPro, the error message appears in the status bar at the bottom of the main Visual FoxPro window.

Press ESC to close the Browse window.

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE products && Open products table IF _WINDOWS OR _MAC SET STATUS BAR ON ENDIF USE products BROWSE FIELDS in_stock :V = in_stock < 100 ; :F ; :E = 'The stock amount must be less than 100'
:P = cFormatCodes

If you include a FIELDS clause, you can also specify a picture option (:P) for each field in the list. The picture option lets you create a list of codes that controls the display and input of data for each field in a Browse window. cFormatCodes is the list of codes.

The following example uses the picture option to allow only numeric data in a specific format to be entered in the unit_price field:

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE products && Open products table BROWSE FIELDS unit_price :P = '99,999.99'

See the Format Property and InputMask Property properties for more information about picture option codes.

:B = eLowerBound , eUpperBound [:F]

Specifies a set of boundaries between which data in a field must fall. The boundary expressions eLowerBound and eUpperBound must match the data type of the field. They cannot be user-defined functions. If the data entered doesn't fall between eLowerBound and eUpperBound , a system error message appears indicating the range within which the data must fall.

By default, the data you enter is checked against the boundary values only if you make a change to the contents of the field. To force checking against the boundary values, include the forced validation option (:F).

The following example ensures that the value in the in_stock field falls between 1 and 100. Press ESC to close the Browse window.

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE products && Open products table BROWSE FIELDS in_stock :B = 1, 100 :F
:H = cHeadingText

Replaces the default field names with your own headings, which you specify with cHeadingText . By default, field names are used as the column headings in the Browse window.

The following example provides user-defined headings for the displayed fields.

CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE products && Open products table BROWSE FIELDS prod_name :H = 'Product Name:', ; unit_price :H = 'Price per Unit:'
:W = lExpression2

Determines whether the cursor can be moved to a field. If lExpression2 evaluates to false (.F.), moving the cursor to the field is prohibited. If lExpression2 evaluates to true (.T.), the cursor can be moved to the field. User-defined functions are supported in lExpression2 .

If moving the cursor to all fields is prohibited, the current record is marked read-only. This occurs only when every field contains a WHEN clause that evaluates to false.

SET SKIP Support SET SKIP lets you establish a one-to-many relationship between two tables. For each record in the parent table, there can be multiple related records in the child table. If you create a one-to-many relationship, you may use BROWSE to view records from both the parent and child tables.

The parent record appears once, along with the first matching record from the child table. Any subsequent matching records are displayed in the rows following the parent record and first matching child record. The fill character for repeated parent information depends on the current Browse window font.

If the record pointer is positioned on a parent record, you can move the pointer through the parent records in the Browse window by pressing CTRL+DOWN ARROW to move to the next parent record or CTRL+UP ARROW to move to the previous parent record. For more information on creating one-to-many relationships, see SET SKIP Command .

The FIELDS clause field list contains records from both the parent and child tables. The names of fields are prefaced with their table alias ( orders or customer ) and a period.

CLEAR CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE customer ORDER cust_id IN 0 && Parent table USE orders ORDER cust_id IN 0 && Child table SELECT customer && Back to parent work area SET RELATION TO cust_id INTO orders && Establish relationship SET SKIP TO orders && One-to-many relationship WAIT WINDOW 'Scroll to see shipping dates for each customer' NOWAIT BROWSE FIELDS customer.cust_id :H='Customer Number', ; customer.city :H='Customer City', orders.shipped_on

Useful Functions Several Visual FoxPro functions return useful information about a Browse window.

Returns the name of the field the cursor is in for the active Browse window.

Returns the record number of the selected record in the active Browse window.