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 |
---|---|
Select all text when user enters the text box using the keyboard. |
|
Determine values that can be typed in the text box. |
|
Determine how values are displayed in the text box. |
|
Reference or change the text displayed in the text box in code. |
|
Store the value displayed in the text box in the Value property and in the variable or field specified by the ControlSource property. |
|
Display a dynamic list of previously entered values to chose. |
|
Specify the table that populates the dynamic list for the text box. |
|
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 |
---|---|
Sets whether the first two digits of the year are displayed or not. |
|
Formats the date in the text box to one of fifteen predetermined formats, such as German or Japanese. |
|
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
Reference
Controls for Displaying Information
Controls for Manipulating Rows of Data