Partager via


User Input in Text Boxes

The text box is a basic control that makes it possible for users to add or edit data stored in a non-memo field in a table.

The following table describes some of the tasks you can perform with text boxes by setting the appropriate properties.

Property

Action

SelectOnEntry Property

Select all text when user enters the text box using the keyboard.

InputMask Property

Determine values that can be typed in the text box.

Format Property

Determine how values are displayed in the text box.

Value Property

Reference or change the text displayed in the text box in code.

ControlSource Property

Store the value displayed in the text box in the Value property and in the variable or field specified by the ControlSource property.

AutoComplete Property

Display a dynamic list of previously entered values to chose.

AutoCompTable Property

Specify the table that populates the dynamic list for the text box.

AutoCompSource Property

Specify a field in the auto-completion table to associate with the text box.

The Solution.app file in the Visual FoxPro ...\Samples\Solution directory contains examples of how to use text boxes. After you open Solution.app, in the tree view, click Controls, then Text boxes.

Date Values in Text Boxes

Text boxes have several properties that make it easy for users to enter date values. The following table lists properties you can set to control how dates can be entered in text boxes.

Property

Description

Century

Sets whether the first two digits of the year are displayed or not.

DateFormat

Formats the date in the text box to one of fifteen predetermined formats, such as German or Japanese.

StrictDateEntry

Sets StrictDateEntry to 0 - Loose. This makes it possible for a user to enter dates in more flexible formats than the default 99/99/99.

Validating Data in Text Boxes

You can check or verify values in text boxes by including code inside the Valid event for the text box. If the value in the text box is invalid, return False (.F.) or 0 from the code you use to evaluate the text box value in the Valid event. If the Valid event returns False (.F.), Visual FoxPro displays the message "Invalid input".

Note

The control does not lose focus if the Valid event returns False (.F.) or 0.   

For example, suppose you have a text box in which a user can type an appointment date. You can check that the date has not already passed by including the following example code in the Valid event for the text box:

IF CTOD(THIS.Value) < DATE( )
   = MESSAGEBOX("You need to enter a future date",1)
   RETURN 0
ENDIF

If you want to display your own message, include the WAIT WINDOW command or the MESSAGEBOX( ) Function in the Valid event code and return 0. For more information, see WAIT Command and MESSAGEBOX( ) Function.

See Also

Concepts

Controls for Displaying Lists

Reference

Controls for Accepting Input

Controls for Displaying Information

Controls for Manipulating Rows of Data

Controls for Allowing Specific Actions

Controls for Extending Forms