Hi,
I’m working with the calendar example to have Save and Cancel buttons instead of just closing itself when the user selects a date. I need the buttons because I’m also adding a time field to the window.
I would like the Calendar window to get a date from a database and show that date selected in the calendar when the window opens. To show that is the day selected, I would like to keep the bevel button for that day in the pushed position.
However, the code always sets the day of the date it’s given to day 1. It gives a reason for doing this but I still don’t understand. See below:
[code]Function GetDate(d As Date) As Double
//Call this from another window to allow user to select a date
//format: myDate.totalSeconds = Calendar.GetDate(CurrentDate)
//CurrentDate will be month displayed to start with, can be same as myDate
//Take the date given and set the day to one to prevent
//errors when a user advances a month with Jan31 for example
//then update window
mSelectedDate = New Date
mSelectedDate.TotalSeconds = d.Totalseconds
mSelectedDate.Day = 1
Update
//Stop code execution of this window until user chooses a date
Self.ShowModal
//User has picked a date, window is closing, return the new value
Return mSelectedDate.TotalSeconds
End Function
[/code]
Is it best to create another property to hold my initial date? I don’t want to mess anything up by using the calendar window property, mSelectedDate
.
I planned on toggling the button in the Update()
method like this:
[code] For calendarButton As Integer = 0 To 36
DayNum = calendarButton + 2 - dayOfWeek
If dayNum > 0 And dayNum <= monthDays Then
CalendarDateButton(calendarButton).Caption = Str(dayNum)
CalendarDateButton(calendarButton).Visible = True
Else
CalendarDateButton(calendarButton).Visible = False
End If
// Toggle the button of the selected day
bflag = false
// Set d to the currently selected date
d.month = MonthPopup.ListIndex + 1
d.year = Val( YearPopup.text )
d.day = DayNum
if d = mSelectedDate then bflag = true
CalendarDateButton(calendarButton).Value = bflag
Next[/code]
Thank you