Return a Value from a Form Sample

File: ...\Samples\Solution\Forms\Logform.scx

This sample illustrates returning a value from a logon form. The launching form (Logform.scx) uses the DO FORM command to run the logon form and store the return value to a variable (cUser).

DO FORM Login TO cUser

Note

To return a value from a form, the WindowType property of the form must be set to 1 - Modal.

The logon form (Login.scx) makes it possible for a user to enter a user name and a password. Code associated with the Click event of cmdOK checks to make sure that the correct password was entered.

LOCATE FOR UPPER(login.userid) = UPPER(ALLTRIM(THISFORM.txtUserName.Value))

IF FOUND() AND ALLTRIM(password) == ALLTRIM(THISFORM.txtPassword.Value)
   THISFORM.cUser = ALLTRIM(login.userid)
   THISFORM.Release
ELSE
   #DEFINE MISMATCH_LOC "The user name or password is incorrect. Please try again."
   WAIT WINDOW MISMATCH_LOC TIMEOUT 1.5
   THISFORM.txtUserName.Value = ""
   THISFORM.txtPassword.Value = ""
   THISFORM.txtUserName.SetFocus
ENDIF

Code associated with the Unload event of the logon form returns the name of the user, if the user entered the correct password, or an empty string.

RETURN THIS.cUser

See Also

Tasks

Solution Samples

Reference

Visual FoxPro Foundation Classes A-Z

Other Resources

Forms Solution Samples