How to Validate GETs Based on Elements of an Array

ID: Q120294

The information in this article applies to:

SUMMARY

This article explains how to create a series of entry fields on a screen that are based on an array. The example below explores how these array elements can be validated. It also takes into consideration the possibility that these entry fields from an array may not be the first objects on the entry screen. The example does assume, however, that the fields are grouped together in succession.

MORE INFORMATION

1. Type the following code into a program:

      #DEFINE NUMEMPS 10   && number of array elements
      #DEFINE NUMOBJ  3    && number of GETs NOT from array
      #DEFINE MAXLEN  10   && maximum length of each element
      CLEAR

      DIMENSION MyArray[NUMEMPS]

      * These GETs are NOT from an array
      @1,1 GET x DEFAULT SPACE(10)
      @2,1 GET y DEFAULT SPACE(10)
      @3,1 GET z DEFAULT SPACE(10)

      * Assign to each element of the array MAXLEN spaces
      * If an index into the array is not specified ALL
      * elements are initialized to the same value.
      MyArray = SPACE(MAXLEN)

      FOR i = 1 to NUMEMPS
         @ i+NUMOBJ+1,1 GET MyArray[i] ;
            VALID MyValid(@MyArray,_CUROBJ - NUMOBJ) ;
            SIZE 1,MAXLEN
      ENDFOR

      READ CYCLE

      * Because the array is passed by reference, the element
      * pointed to by pArray[indx] can be modified.
      * NOTE: To pass an array to a procedure or function,
      * it must be passed by reference.
      PROCEDURE MyValid
      PARAMETER pArray, indx

      IF !EMPTY(pArray[indx])
         *Add an exclamation point to whatever you type.
         pArray[indx]= PADR(ALLTRIM(pArray[indx])+'!',MAXLEN)
         SHOW OBJECT _CUROBJ   && refresh the GET object
      ENDIF

2. Run the program, and enter values in any of the GETs.

The first three entry fields don't do anything special. They are just dummy GETs for this example so that the array GETs aren't the first objects on the screen.

The validation routine for the GETs bound to individual elements of the array appends an exclamation point to the end of the most recently entered value, provided all entry positions are not filled by user input. This example demonstrates that it is possible to efficiently validate a group of GETs bound to a single array.

Additional reference words: FoxUnix FoxMac FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.50c 2.60 2.60a KBCategory: kbprg kbcode KBSubcategory: FxprgGeneral

Last Reviewed: August 28, 1995