我在玩文化日历。我原以为 GregorianCalendar (和其他人)会是 under 的一种System.Globalization.Calendar
,但事实并非如此。这是一个等同于日历的全球化类。在下面的功能中,我认为我不能做我想做的事,但在报废之前......
我收到有关“cal”在封闭块中隐藏变量的错误,但我确实在dim
语句中将其设置为默认值。Calendar 类似乎没有能力声明然后用文化来绘制它。看来您必须声明“文化”日历类,并且不能更改。您是否找到解决此问题的方法并将其保留在一个简短的函数中?
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))