Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

oleCalendar

Status
Not open for further replies.

Koen Piller

Programmer
Jun 30, 2005
841
NL
Hi,

I am trying to make use of the oleCalendar and have therefor following code (see thread 184-213348)
Code:
#DEFINE C_CALCAPTION_LOC    "Data Calendar"
oCalForm = Create('form')
oCalForm.NewObject("oleCalendar","_olecalendar","_datetime")

WITH oCalForm.oleCalendar
    .date_column = "Date()"
    .RefreshDisplay()
    .BackColor = THISFORM.BackColor
    .Visible = .T.
ENDWITH
WITH oCalForm
    .AutoCenter = .T.
    .BorderStyle = 2
    .MaxButton = .F.
    .MinButton = .F.
    .Height = oCalForm.oleCalendar.Height
    .Width = oCalForm.oleCalendar.Width
    .Caption = C_CALCAPTION_LOC
ENDWITH

oCalForm.Show(1)
THISFORM.Refresh

This brings up the calendar alright, but now I also would like to have the selected date from the calender into my textbox:
Thisform.txtCalenderdate.value

Don’t seem to be able to get the result, how to do?
Regards,
Stay healthy
Koen
 
Koen, there is no specific Value property for the calendar, but there are separate properties for Year, Month, Day, Hour, Minute and Second.

So to get the date into the textbox, you could do something like this:

Code:
WITH oleCalendar
  THISFORM.txtCalenderdate.value = ;
   DATE(.Year, .Month, .Day)
ENDWITH

Alternatively, you could convert those values to strings and then join them together.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Actually, just looking at the internals of _olecalendar, I see that it has a custom property named dValue, which contains the selected date. So you should be able to copy it straight to your textbox. It is a Date data type, so convert it to a character format if that is appropriate.

EDIT: And you would do this in the control's Change event.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Mike,
I suppose we are talking about two different activeX, mine has no dValue property. Also there is no Change event in my activeX.
I am using the _oleCaledar which is shipped with FFC the class in classlibrary _datetime.vcx
Stay healty.
Koen
 
Koen,

Sorry, I was looking at the same class as you, but I assumed it was based on the Microsoft Datetime Picker control (which looks almost identical).

So, instead of the Change event, you need the SelChange event. This "occurs after the user selects a new date or range of dates". And forget about the dValue propety. But what I said about the Year, Month and Day properties still applies. So you can still use that chunk of code I showed you in my first reply above.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Looking further, I see that SelChange takes a parameter, StartDate. So you could place that value straight into your textbox. However, that would give you a datetime rather than a date. If you only want the date element, you can use TTOD() to extract it.

Here is a complete working example:

Code:
SET CLASSLIB TO _datetime.vcx ADDITIVE
oform1=NEWOBJECT("form1")
oform1.SHOW

DEFINE CLASS form1 AS FORM

    TOP = 0
    LEFT = 0
    HEIGHT = 270
    WIDTH = 352
    CAPTION = "Calendar"
    WindowType = 1
    NAME = "Form1"

    ADD OBJECT olecalendar AS _olecalendar WITH ;
        TOP = 23, ;
        LEFT = 39, ;
        NAME = "oleCalendar"


    ADD OBJECT txtCalendarDate AS TEXTBOX WITH ;
        HEIGHT = 23, ;
        LEFT = 36, ;
        TOP = 228, ;
        WIDTH = 192, ;
        NAME = "txtCalendarDate"

    PROCEDURE olecalendar.SelChange
      LPARAMETERS StartDate, EndDate, CANCEL

      THISFORM.txtcalendardate.VALUE = TTOD(StartDate)
    
    ENDPROC

ENDDEFINE

If you run this, check that the VCX is in your search path.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top