Function ReadVar() Foundation

Determines name of the current GET or MENU TO variable.

Syntax
ReadVar() --> cVariableName
Return

ReadVar() returns the name of the variable in the current GET or MENU TO command as a character string.

Description

The environment function ReadVar() returns the variable name as a character string which was specified in the command GET or MENU TO. The variable name is only returned if one of these two commands were executed. Using ReadVar(), a context sensitive help system can be created based on the name of the variable specified to store the MENU TO result or identified as an input field of a Get.

Examples
Help system with ReadVar()
// The example shows a simple help system based on 
// ReadVar(). When the F1 key is pressed, help text is 
// displayed using MemoEdit() and information stored in 
// a memo file. Depending on the #define constant DEBUG, 
// the help text can be edited or just displayed at runtime. 
// Using this technique, help text can be written at runtime 
// during development of a program while the delivery version 
// of the program only allows help text to be displayed. 

#include "Inkey.ch" 

#define  DEBUG // help texts can be edited at runtime 

PROCEDURE Main 
   LOCAL nMainMenu 
   IF ! File("HELP.DBF") 
      DbCreate("HELP", { { "READVAR" , "C", 10, 0} ,; 
                         { "HELPTEXT", "M", 10, 0} } ) 
      USE HELP NEW EXCLUSIVE 
      INDEX ON Readvar TO HELP 
   ENDIF 

   SET KEY K_F1 TO Help 

   DO WHILE .T. 

      @ 10,10 PROMPT "Customer screen" 
      @ 11,10 PROMPT "Parts screen" 
      MENU TO nMainMenu 

      DO CASE 
      CASE nMainMenu == 0 
         CLOSE ALL 
         EXIT 
      CASE nMainMenu == 1 
         Customers() 
      CASE nMainMenu == 2 
         Parts() 
      ENDCASE 
   ENDDO 

RETURN 

******************* 
PROCEDURE Customers 
   CLS 

   USE Customer NEW 
   @ 10,10 SAY " Last name:" GET Customer->Lastname 
   @ 11,10 SAY "First name:" GET Customer->Firstname 
   READ 

   CLOSE Customer 
RETURN 

*************** 
PROCEDURE Parts 
   CLS 

   USE Parts NEW 
   @ 10,10 SAY "Part No:" GET Parts->PartNo 
   @ 11,10 SAY "   Part:" GET Parts->Part 
   READ 

   CLOSE Parts 
RETURN 

************** 
PROCEDURE Help 
   LOCAL nArea := Select() 

   IF Select("HELP") == 0 
      USE Help INDEX Help NEW 
   ENDIF 

   SELECT Help 
   SEEK Upper( ReadVar() ) 

   IF Found() 
      ShowHelpText( Help->HelpText ) 
   ELSE 
      #ifdef DEBUG 
         APPEND BLANK 
         REPLACE Help->Readvar WITH Upper( ReadVar() ) 
         ShowHelpText( Help->HelpText ) 
      #else 
         ShowHelpText("No help available") 
      #endif 
   ENDIF 
   DbSelectArea( nArea ) 
RETURN 

********************** 
PROCEDURE ShowHelpText( cHelpText ) 
   LOCAL cScreen := SaveScreen( 2, 2, 22,78 ) 

   DispBox(  2, 2,22,78, 2 ) 

   #ifdef DEBUG                    // help texts can be edited 
     REPLACE Help->HelpText WITH ; // in the DEBUG version 
        MemoEdit(cHelpText, 3, 3, 21, 77, .T. ) 
   #else 
     SET CURSOR OFF                // help texts can only be 
                                   // displayed in the 
                                   // delivery version 
     MemoEdit(cHelpText, 3, 3, 21, 77, .F.) 
   #endif 

   RestScreen(2, 2, 22, 78, cScreen) 
   SET CURSOR ON 

RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.