Return a Value from a Form

File: SAMPLES\SOLUTION\FORMS\LOGFORM.SCX

This sample illustrates returning a value from a login form. The launching form (LOGFORM.SCX) uses the DO FORM command to run the login 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 login form (LOGIN.SCX) allows 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 login form returns the name of the user, if the user entered the correct password, or an empty string:

RETURN THIS.cUser