I am playing with culture calendars. I would have thought GregorianCalendar (and the others) would be a type of under System.Globalization.Calendar
, but it's not. It's a Globalization class equal to Calendar. In the function below, I don't think I can do what I want to do, but before a scrap it...
I am getting error about "cal" hides a variable in an enclosed block but I did set it to a default in the dim
statement. The Calendar class does not seem to have the ability to declare and then paint it with a culture. It seems you have to declare the "cultural" calendar class and it cannot be changed. Do you see a way around this and keep it in a short function?
Public Function GetDaysInMonth(ByVal dt As Date,
Optional ByVal sCalendar As String = "GREGORIAN") As Integer
Dim cal As System.Globalization.GregorianCalendar
Dim y, m As Integer
Select Case UCase(sCalendar)
Case "HEBREW"
Dim cal As New HebrewCalendar
Case "HIJRI"
Dim cal As New HijriCalendar
Case "JAPENESE"
Dim cal As New JapaneseCalendar
Case "JULIAN"
Dim cas As New JulianCalendar
Case "KOREAN"
Dim cal As New KoreanCalendar
Case "TAIWAN"
Dim cal As New TaiwanCalendar
Case "THAIBUDDHIST"
Dim cal As New ThaiBuddhistCalendar
Case Else 'Gregorian
End Select
y = Year(dt)
m = Month(dt)
Return (cal.GetDaysInMonth(y, m))