You are here:

FoxPro/Gotfocus functionality


QUESTION: I am using foxpro 2.6 for DOS.  There are few @ say.. get variable have been placed on the screen.  Suppose user is in the get region of var1 then I wish to have a message like "You are in the var1" as he enters in the var1 variable.  As he press enter or tab key, the respective message should be displayed like "You are in the var<N>".

Problem is @ get valid(myfunc(varread()) is only executed when user exits from the get variable, I need it to be executed as he enters in the get region.

Kindly help me with an example of action code please.

Girish Sharma

ANSWER: Good morning, well - here it is...

  You are correct about the VALID clause - it executes as control passes out of the variable.  The WHEN clause executes as control passes into the variable.  Usage is the same, only execution time is different.

  I don't have time (at the moment) to give you detailed code, but if you need additional help, please post a follow-up question and I'll assist in any way I can.  I wanted to give you an answer quickly and, since you are familiar with VALID, you should be okay.

Good Luck,


---------- FOLLOW-UP ----------

QUESTION: I am thankful to you for your fast and helpful reply.  Yes, I need additional help by viewing the WHEN clause so that I may get it into my .PRG file.  Here it is more details of my current work:

I have below code :

set talk off
set status off
close all
use stu
set order to rollno
@ 5,5 say 'Enter Rollno:-' get rol default space(7) pict "@K"
seek rol
@ 7,5  get mark1 valid myfunc(varread())
@ 7,10 get mark2 valid myfunc(varread())
@ 7,15 get mark3 valid myfunc(varread())
@ 7,20 get mark4 valid myfunc(varread())
@ 7,25 get mark5 valid myfunc(varread())

function myfunc
parameter varname
do case
case varname='MARK1'
@20,20 say 'You are in Mark1'

case varname='MARK2'
@20,20 say 'You are in Mark2'
@20,20 say space(20)

I need to display and/or process some more other code as and when user navigates in the different get variables.

Kindly help me.

Thanks and Regards
Girish Sharma

Although the WHEN clause was not strictly designed for this, if you change your code by replacing "VALID" with "WHEN" it will do what you want.  The original purpose of WHEN was to programmatically control if an object should be allowed to work.  If the result of the WHEN clause returns 0 (zero) or .F. (false), the field cannot be entered.  IF the result returns non-zero (usually a 1 [one]) or .T. (true), then entry into the field is permitted.  However, since the code is executed as soon as entry into the field is attempted (via a click, tab, arrows, etc.) you should see the desired behavior.

The subject of your question "GOTFOCUS FUNCTIONALITY" threw me a curve, since the GOTFOCUS method does not exist in FoxPro versions prior to Visual FoxPro.  But, with the WHEN clause, the concept is the same.

Just remember to RETURN .T. at the end of your WHEN clause so entry into the field is allowed.

Best of luck,



All Answers

Answers by Expert:

Ask Experts


Fred Frase


Questions about development only. No installation or hardware specific questions, please. Your first step in requesting assistance should be to identify the version of FoxPro you are using. I can write short functions but, PLEASE do not ask me to write programs for you.


Nearly 30 years professional programming experience using FoxPro (FoxBase through VFP 9) or other xbase language, primarily in Windows environments.

Completed a 1,000 hour diploma course in programming at International Academy of Ohio (subsequently merged with Southern Ohio College).

©2017 All rights reserved.