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!

Problem using oleCalendar 1

Status
Not open for further replies.

k2a

Programmer
Jun 26, 2012
133
DE
I use the oleCalendar in a form and it works fine, like this:

#DEFINE C_CALCAPTION_LOC "Abgleich-Kalender"
oCalForm = Create('form')
oCalForm.NewObject("oleCalendar","app_olecalendar","libs\mahnwesen_app.vcx")
IF EMPTY(thisform.Abgleichtag.Value) then
thisform.Abgleichtag.Value = DATE() && ControlSource is linked to view lv_abgleich.mzy_datum
EndIf
WITH oCalForm.oleCalendar
.date_column = "lv_abgleich.mzy_datum"
.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)

Now, in another form the same method is used except that the textbox Abgleichtag in not linked to a view any more and therefore I changed the statement “ .date_column = "lv_abgleich.mzy_datum" to .date_column = "thisform. Abgleichtag.Value".

However, this returns an error message “Unknown member Abgleichtag”.

Has someone an idea how to solve this problem?

Klaus
 
In the context of another form you can specify a viewname.field, as you did, because the calendar form uses the same datasession. But it's adifferent form, it has no member Abgleichtag. The error is very clear about that.

One thing you could do is use a cursor, the other would be using a private or public variable, but you can't specify a property of the current form, as it's not a property of the calendar form.

Code:
CREATE CURSOR curDATE (dDate D)
Insert Into curDATE Values (DATE())
...
.date_column = "curDate.dDate"

Bye, Olaf.
 
As you generate a form base class via oCalForm = CreateObject('form'), you could also create a specific form class for the oleCalendar, one with the oleCalendar already inserted would be straight forward, then you'd not need to set all these values at runtime in the WITH...ENDWITH code.

You can of course also add the needed property via oCalForm.AddProperty("yourdate",DATE()) and then set the olecalendar.date_column = "thisform.yourdate", finally read out oCalForm.yourdate.

Bye, Olaf.

 
Olaf, thanks again for your great help.

The first solution you gave me should have solved my problem, but for some reason the cursor curDate gets not updated to the selected date chosen from oleCalendar.

After the setup the cursor curDate has the value 14.01.2013 but in the oleCalendar object the procedure SelChange has a statement “Replace &cColumn With m.dValue”.
So, cColumn = “curDate.dDate” and m.dValue = {30.01.2013} but after the update the cursor content did not change, it still keeps the old value of 14.01.2013.

Every looks good, but why does the update fail?

Regards,
Klaus
 
Well with that macro substitition it fails, but it would also fail with lv_abgleich.mzy_datum.

The replace command should be REPLACE field WITH m.dValue IN alias, so you would need two properties in the oleCalendar for the view/cursor/alias name and the field.

Replace curDATA.dDate with m.dValue will fail, if the record pointer is at EOF of the currently selected workarea. The clause IN curDATA would assure the replace success depends on the record pointed to in the curDATA cursor, and would then not fail.

You can see this behavior in action this way, creating 2 cursors and using the one and the other REPLACE variant:

Code:
CREATE CURSOR curUpdate (dDate D)
INSERT INTO curUpdate Values (DATE())
? ALIAS(), EOF(ALIAS())

CREATE CURSOR curSelected (cSomething C(10))
? ALIAS(), EOF(ALIAS())

Replace curUpdate.dDate With Date()+1 && does not replace
? curUpdate.dDate

Replace dDate With Date()+2 In curUpdate && does replace
? curUpdate.dDate

As you'll see the first ? curUpdate.dDate will not display DATE()+1 as you expect, but the original DATE() value. The previous REPLACE did not replace, because if you don't specify an IN clause the replace happens in the curSelected alias, but nothing happens there and in curDate, as a) there is no field dDate in curSelected, and b) the record pointer is at EOF in curSelected, so even if you'd specify dDate without alias prefix or if you'd specified the cSomething field, nothing would be replaced, as by design REPLACE doesn't work at EOF().

That said the situation as it was before, with the view, would also only work, if the view is the currently selected alias. And if you create curDate jsut before you call the calendar form, it would be the currently selected alias, so it should work the same way, because Replace curUpdate.dDate With m.dValue does work, when curDate is selected.

Bye, Olaf.
 
Thank you Olaf for your detailed explanation.

Now the solution was quite simple, I just select the cursor before entering the oleCalendar object and this time the cursor gets updated with the selected date.

I’m very glad you solved it.

Regards
Klaus
 
> I just select the cursor before entering the oleCalendar object
Well, you should not have to do that, if you CREATE CURSOR curDATE, it is already the selected cursor, that code was meant to be added to your code right before the call of the calendar.

Besides there is a much easier way of updating a field, by making the same expression the controlsource of some additional textbox on the calendarform, because you don't have to do a REPLACE, the controlsource is bidirectional and writes to the field, as you surely know. The only thing to do then would be setting the conttrolsource and finally instead of the replace do thisform.textbox.value = m.dValue

Last not least, if there is a variable m.dValue, why not make a form class returning it, instead of this complicated "wiring"?

Bye, Olaf.
 
Okay Olaf, there might be some more better ways to use the oleCalendar, but for the time being I stick with first solution I have now. To try something else right now is really a pain, because after each small modification the VFP stops and must be restarted. I have to solve that problem first and try what you have suggested, regarding my SSD issue.

However, I have a final question concerning the oleCalendar. On the popup calendar the bar with the days on it are almost invisible on my screen. Is there a possibility to change the contrast or the color on it?

Regards,
Klaus

 
I don't know what you're using OCX wise, as mahnwesen_app.vcx is not part of the FFC or sample code of foxpro ;)

Well, if that is based on the MS Date Time Picker, you can change several colors, but not the Week day fore color. You can make the backcolor black and forecolor white, then weekdays are easier to read:

Code:
this.calendarBackColor = Rgb(0,0,0)
this.calendarForeColor = Rgb(255,255,255)

That looks awkward, though, if any other control has a white background.

Bye, Olaf.
 
I played around some more: It seems the weekdays forecolor depends on the calendarTitleBackColor, eg test

Code:
this.calendarTitleBackColor = Rgb(0,0,255)
this.calendarTitleForeColor = Rgb(255,255,255)

Bye, Olaf.
 
Excellent, with the selection of the title color the calendar can now be fine-tuned.

Thanks a lot Olaf!

Regards,
Klaus
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top