How to Make a Day Date Spinner

Last reviewed: September 14, 1995
Article ID: Q136666
The information in this article applies to:
  • Microsoft Visual FoxPro for Windows, version 3.0

SUMMARY

The "Using Spinners" section in chapter 11 of the Visual FoxPro Developer's Guide gives the following incorrect information:

   If you want a user to be able to spin through a range of dates,
   you could size the spinner so that only the buttons are visible and
   position a text box beside the spinner buttons.

It is not possible to size a spinner so that only the buttons are visible. The example in this article shows how to make a Day Date spinner and make it appear to be a single control.

MORE INFORMATION

  1. Create a new class called DayDateSpin based on Container.

  2. Store it in MyLib.vcx.

  3. Set the following properties for the DayDateSpin container:

    BackStyle = 0 - Transparent BorderWidth = 0 Height = 24 Width = 164

  4. Add a text box to the container, and set these properties:

       FontName = Courier New   && Or any nonproportional font
       FontSize = 9
       Format = k    && Highlights the text box when the focus gets set to it.
       Height = 22
       Left = 0
       ReadOnly = .T. && Keeps the user from editing the text box
       Top = 1
       Width = 148
    
    

  5. In the Init event procedure of the text box, add this code:

    THIS.Value = PADR(CDOW(DATE()),11) + DTOC(DATE()) ** This puts current day and date in the text box when the form starts

  6. Add a spinner to the container and set these properties:

    FontSize = 1 Height = 24 Left = 146 Top = 0 Width = 18

  7. On the Format menu, click Send to Back

  8. Add the following code to the spinner's DownClick event procedure:

    dMyDate = CTOD(RIGHT(ALLTRIM(THIS.PARENT.Text1.Value),8)) ** Gets the Date from the text box dMyDate = dMyDate - 1 && Decrease the date by one THIS.PARENT.Text1.Value = PADR(CDOW(dMyDate),11) + DTOC(dMyDate) **Stores the new day of the week and date back into the text box THIS.PARENT.Text1.SetFocus

  9. Add the following code to the spinner's UpClick event procedure:

    dMyDate = CTOD(RIGHT(ALLTRIM(THIS.PARENT.Text1.Value),8)) ** Gets the Date from the text box dMyDate = dMyDate + 1 && Increment the date by one THIS.PARENT.Text1.Value = PADR(CDOW(dMyDate),11) + DTOC(dMyDate) **Stores the new day of the week and date back into the text box THIS.PARENT.Text1.SetFocus

  10. Save and close the class.

  11. Create a new form. Then click the View Classes Icon on the Form

        Controls toolbar. Click Add, and select MyLib.vcx.
    

  12. Pick the DayDateSpin class from the Form Controls toolbar, and place it

        on the form.
    

  13. Save and run the form. Click the up arrow or down arrow to see the day

        and date go up or down.
    

REFERENCES

For more infromation about creating classes and working with Visual FoxPro controls, please see chapters 10 and 11 in the Developer's Guide.


Additional reference words: 3.00 VFoxWin
KBCategory: kbui kbprg kbcode kbdocerr
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 14, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.