Partager via


Controls for Accepting Input

It is not always possible to anticipate all the possible values that a user might need to enter into a control. The following controls make it possible for you to accept user input that cannot be predetermined:

  • Text boxes
  • Edit boxes
  • Combo boxes

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

To see examples of using text boxes

  1. Run Solution.app in the Visual FoxPro ...\Samples\Solution directory.
  2. In the tree view, click Controls, and then click Text boxes.

To programmatically reference or change the text displayed in the text box

  • Set or reference the Value property.

If you set a ControlSource for the text box, the value displayed in the text box is stored in the Value property of the text box and in the variable or field specified in the ControlSource property.

Validating the Data in a Text Box

To check or verify the value in the text box, include code in the method associated with the Valid event. If the value is invalid, return False (.F.) or 0. If the Valid returns False (.F.), an "Invalid input" message is displayed. If you want to display your own message, include the WAIT WINDOW command or the MESSAGEBOX( ) function in the Valid code and return 0.

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

For example, if you have a text box that makes it possible for a user to type an appointment date, you could check to make sure that the date is not already past by including the following code in the Valid event of the text box:

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

Selecting Text When the Text Box Gets the Focus

To select all text when the user enters the text box with the keyboard, set the SelectOnEntry property to True (.T.).

Formatting the Text in a Text Box

You can use the InputMask property to determine the values that can be typed in the text box and the Format property to determine the way values are displayed in the text box.

See Also

Using Check Boxes | Using the InputMask Property | Using Controls | Value | Accepting Numeric Input in a Given Range | Controls and Objects