How to Validate GETs Based on Elements of an Array

Last reviewed: August 28, 1995
Article ID: Q120294
The information in this article applies to:
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5x, 2.6, 2.6a
  • Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a
  • Microsoft FoxPro for Macintosh, versions 2.5x, 2.6a
  • Microsoft FoxPro for UNIX, version 2.6

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 28, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.