Validating User Input with Xbasic

Description

Frequently you will wish to force a user's input to a form field to be non-blank, within a range, or one of several values. You can achieve these effects with Field Rules, but you can also code them with Xbasic.

Example:

The following code attached to the CanDepartevent of the Emailtext field reminds the user to enter a non-blank value.

if (alltrim(Email.text) = "") then
    ui_beep()
    cancel()
end if

This code attached to the CanDepartevent of the quantityfield checks that the value is within the range 1 to 100.

if alltrim( quantity.text ? < 1) .or. alltrim( quantity.text ?> 100) then
    ui_msg_box("Invalid Value", "The value entered must be between 1 and 100")
    cancel()
end if

This code attached to the CanDepartevent of the namefield checks that the value is contained within a pre-determined list. This technique might be used as a low-level security mechanism. Most users would find a list boxmore friendly.

dim list as C
list= <