# Visual Basic的函數問題

----------------------------------------------------------------------------------------

Function Calc_Leap_01%(Y%)

Dim West_Y%

West_Y% = Y% + 1911

Calc_Leap_01% = (West_Y% Mod 4 = 0 And West_Y% Mod 100 <> 0) Or (West_Y% Mod 400 = 0)

End Function

----------------------------------------------------------------------------------------

Function Calc_Days_of_Month%(Y%, M%)

Select Case M%

Case 1, 3, 5, 7, 8, 10, 12:

Calc_Days_of_Month% = 31

Case 4, 6, 9, 11:

Calc_Days_of_Month% = 30

Case 2:

If Calc_Leap_01%(Y%) = -1 Then

Calc_Days_of_Month% = 29

Else

Calc_Days_of_Month% = 28

End If

Case Else:

Debug.Print Policy_No\$

Stop

End Select

End Function

----------------------------------------------------------------------------------------

Calc_Leap_01% = (West_Y% Mod 4 = 0 And West_Y% Mod 100 <> 0) Or (West_Y% Mod 400 = 0)

Rating
• 提姆
Lv 5

Q1:閏年的條件：

當西元年為４的倍數且非１００的倍數

或西元年為４００的倍數

今年為2008，代入

(West_Y% Mod 4 = 0 And West_Y% Mod 100 <> 0) Or (West_Y% Mod 400 = 0)

＝(2008 Mod 4 = 0 And 2008 Mod 100 <> 0) Or (2008Mod 400 = 0)

＝(True And True) Or False

＝True

Q2

(-1)即為True.