How to Change a Field Color Based on the Field's Contents

Last reviewed: April 30, 1996
Article ID: Q114254
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6
  • Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, 2.5a, 2.5b, 2.6

SUMMARY

This article describes how to change the color of a field based on its contents. Changing the color of a field based on what it contains may be useful to users who are scrolling through the records in an input screen.

MORE INFORMATION

To create the screen, do the following:

  1. Open the CUSTOMER.DBF database located in the TUTORIAL subdirectory.

  2. Create a screen and choose Quick Screen from the Screen menu.

  3. Add two push buttons to the screen with the variable name M.CHOICE. Give the push button two prompts called PRIOR and NEXT. Enter the following code in the VALID clause:

          DO CASE
    
             CASE m.choice = 1
                SKIP - 1
             CASE m.choice = 2
                SKIP
          ENDCASE
          SHOW GETS
    
    

  4. If you are using FoxPro for Windows, choose Layout from the Screen menu. Choose the Code push button and add the following code in the On Refresh (Show Gets) box:

          IF customer.lat > 35
    
             SHOW GET customer.lat COLOR ,RGB(255,255,255,255,0,0)
          ELSE
             SHOW GET customer.lat COLOR ,RGB(0,0,0,192,192,192)
          ENDIF
    
          NOTE: To change the numbers used in the RGB() clause, double-click
          the Color icon in the Windows Control Panel. Choose the Color Palette
          button, select the color you want to know the numbers of, and then
          choose the Define Custom Colors button. The numbers in the Red,
          Green, and Blue boxes are the ones you use with RGB(). The first
          three numbers in the RGB() clause are the foreground and the last
          three numbers are the background.
    
       If you are using FoxPro for MS-DOS, choose Screen Layout from the Screen
       menu. In the SHOW clause, add the following code:
    
          IF customer.lat > 35
             SHOW GET customer.lat COLOR +W/R
          ELSE
             SHOW GET customer.lat COLOR +W/BG
          ENDIF
    
    
If customer.lat is greater than 35, the field will have a white foreground and red background. If customer.lat is less than 35, the field will have the default colors of a white foreground with cyan background in FoxPro for MS-DOS and a black foreground with gray background in FoxPro for Windows.


Additional reference words: FoxDos FoxWin 2.00 2.50 2.50a 2.50b 2.60 set
KBCategory: kbprg
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: April 30, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.