How to Simulate Date Spinners by Using a Set of Buttons

Last reviewed: September 26, 1995
Article ID: Q137181
The information in this article applies to:
  • Microsoft FoxPro for Windows, versions 2.5, 2.5a, 2.5b, 2.6, 2.6a

SUMMARY

FoxPro for Windows includes the data entry object called a Spinner control to help users enter numeric data. This article shows you how to create a simulated Date Spinner control to help users choose a date. The technique involves using a set of buttons with a date field to create the simulated Date Spinner control. A third button is included to allow the user to clear the date or set it to the current system date.

MORE INFORMATION

The main function of the Date Spinner buttons is to increase or decrease the value of the date by one or more days. FoxPro supports date arithmetic. Adding a whole number to a date changes the date to the date that is that number of days in the future. Subtracting a whole number from a date changes the date to the date that is that number days in the past.

The example in this article uses three buttons. The Plus and Minus buttons add or subtract one from the date field. If the date field is empty, the buttons set it to the current system date.

The optional third button has two functions. When the date field has a value, the third button displays the letter C to indicate that it will clear the date value. When the date field is empty, the third button displays the letter T to indicate that it will set the day to today's date. This is not a feature you would normally find with a Spinner object, but it can be a handy one for data entry.

Steps to Create Date Spinners by Using Buttons

  1. Create a screen in FoxPro that contains a date field.

  2. To the right of the date field, place a button set of three buttons, and label the buttons +, -, and C. Adjust the size of the button set by clicking the lower-right corner of the set and dragging it up and to the left until it becomes as small as possible. You may want to choose a smaller font size as well. In this example, the name of the date field is m.lddate and the name of the button set is m.lnspinner.

  3. Place the following code in the WHEN for the m.lnspinner button set:

    IF EMPTY(m.lddate)

          SHOW GET m.lnspinner, 3 PROMPT "T"
    
    ELSE

          SHOW GET m.lnspinner, 3 PROMPT "C"
    
    ENDIF

    This adjusts the prompt for the third push button. When the date field is empty, the prompt for the third push button will be T, otherwise it will remain as C.

  4. Place the following code in the VALID for the m.lnspinner button set :

    DO CASE

          CASE m.lnspinner = 1  && clicked + button
    
             IF EMPTY(m.lddate)
                m.lddate = DATE()
             ELSE
                m.lddate = m.lddate + 1
             ENDIF
             SHOW GET m.lddate
          CASE m.lnspinner = 2  && clicked - button
             IF EMPTY(m.lddate)
                m.lddate = DATE()
             ELSE
                m.lddate = m.lddate - 1
             ENDIF
             SHOW GET m.lddate
          CASE m.lnspinner = 3  && clicked C or T button
             IF EMPTY(m.lddate)
                m.lddate = DATE()
             ELSE
                m.lddate = {}
             ENDIF
             SHOW GET m.lddate
       ENDCASE
    
       When the first button (+) is clicked, the date is increased by one day.
       When the second button (-) is clicked, the date is decreased by one day.
       In either case, if the date field is empty, it is set to the current
       system date. When the third button (C or T) is clicked, if the date
       field is empty, it is set to the current system date, otherwise it is
       set to an empty date value.
    
    

  5. Save the screen, and generate the screen program. When you run the program you will now have buttons that act like a Spinner control for your date field.


Additional reference words: 2.50 2.50a 2.50b 2.60 2.60a date spinner FoxWin
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: September 26, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.