Date Picker

I use IsDate or DateSerial functions in VB6 to check. I am still new to Xojo and I have searched and I think equivalents may not be available.

Converting from the logic in VB6, here is a simple Xojo code to check for leap year. Change the inputYear 2015 or 2016 to see the result.

[code] Dim inputDay As Integer
Dim inputMonth As Integer
Dim inputYear As Integer

Dim returnedDay As Integer
Dim returnedMonth As Integer
Dim returnedYear As Integer

Dim d As New Date
Dim leapYear As Boolean

// Date to check
inputDay = 29
inputMonth = 2
inputYear = 2016

// Assign into d
d.day = inputDay
d.month = inputMonth
d.year = inputYear

// Retrievd Xojo computed date
returnedDay=d.day
returnedMonth = d.month
returnedYear = d.year

// Check for Leap Year
leapYear = (inputMonth = returnedMonth) And (inputDay = returnedDay)

// Message
If leapYear Then
MsgBox d.ShortDate.ToText + " is a Leap Year"
Else
MsgBox d.ShortDate.ToText + " Not Leap Year"
End If[/code]

Function isLeapYear(year As Integer) As Boolean
  
  // Returns True if a year is a leap year
  If ((year Mod 4 = 0) And (year Mod 100 <> 0)) Or (year Mod 400 = 0) Then Return True
  
End Function
1 Like

[quote=248638:@Marco Hof][code]
Function isLeapYear(year As Integer) As Boolean

// Returns True if a year is a leap year
If ((year Mod 4 = 0) And (year Mod 100 <> 0)) Or (year Mod 400 = 0) Then Return True

End Function
[/code][/quote]

Function calcLeapYear(inYear As Integer) As Boolean
  Return (((inYear MOD 4)=0) AND ((inYear MOD 100)<>0)) OR (inYear MOD 400)=0
End Function

Mine is almost identical from the Calendar and Time Chooser project.
:slight_smile:

date.DayOfYear of December 31: if it is 366 the year is a leap year.

https://github.com/ejamroz/DatePicker

I get an “Invalidargumentexception” and an “Outofboundexception” . It looks promising but still needs some work.

2018r4 / win10

just try this on Mojave with Xojo 2018r4 and it start and end right away. Can’t even get the error message like Joost has

Spontaneous quitting, that is very strange
 I will investigate.

As for windows 10 I have not tested it on windows, but not sure why one would get an out of bounds exception
 Can you run it in the debugger and break on exceptions please? Let me know where it is going out of bounds, I can not get it to exhibit this behavior. Is the invalid argument a DateModule.Invalid argurment or Xojo.core?

This is very strange. I would love some input on this problem. So, if you download the project, create a new window and put a CalendarPicker on it, set that new window to be what opens when the app loads, everything runs fine. Save the project, try again, everything is fine. But, if you close the project, reopen it and try to run it, it will spontaneously quit.

This behavior is visible on Xojo 2018 r4,r2, and 20173r3

Ok, I got it. I do not know why, but for some reason the computed properties for multi-date and allow past date were getting referenced at startup (even if I removed all references from the code). But, those were getting referenced before the calendar was initialized, causing it to not have any days loaded -> outofbounds exception. I moved the internal call to refresh the UI out of those properties and allowed it to be accessed from outside via refresh(). So, if one changes either of those properties after the calendar is initialized, they will they have to manually call a refresh to update the calendar (this is demonstrated in the example project).

Thank you for taking a look at it. Let me know what else breaks or can be better!

This is a known behaviour of computed properties, and is by design

[quote=425230:@erin jamroz]Ok, I got it. I do not know why, but for some reason the computed properties for multi-date and allow past date were getting referenced at startup (even if I removed all references from the code). But, those were getting referenced before the calendar was initialized, causing it to not have any days loaded -> outofbounds exception. I moved the internal call to refresh the UI out of those properties and allowed it to be accessed from outside via refresh(). So, if one changes either of those properties after the calendar is initialized, they will they have to manually call a refresh to update the calendar (this is demonstrated in the example project).

Thank you for taking a look at it. Let me know what else breaks or can be better![/quote]

what do i need to adjust to make it run??

@Richard Duke I pushed new code, so pull again and it should work.
v1.0.1.
I just tested it again and it works.

[quote=425243:@erin jamroz]@Richard Duke I pushed new code, so pull again and it should work.
v1.0.1.
I just tested it again and it works.[/quote]
thanks/
working now


Great job. Thanks for sharing it.