Visual Basic的函數問題

最近在看前輩留下的VB,由於程式是自學有些不明白的地方想請教各位先進

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

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

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

這是個算潤年的function

想請教的是,在第一個function裡,

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

這個值不是(1 AND 1) or 1 =1 嗎?? <===假設Y以今年97年為例

那在第2個function裡為何是-1才會代入二月是29天呢??

還是我對第一個function的算法有誤解...

謝謝各位大大指點

1 Answer

Rating
  • 提姆
    Lv 5
    1 decade ago
    Favorite Answer

    Q1:閏年的條件:

    當西元年為4的倍數且非100的倍數

    或西元年為400的倍數

    今年為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.

Still have questions? Get your answers by asking now.