天天看點

VB程式設計:IsNumeric判斷閏年

運作效果:

VB程式設計:IsNumeric判斷閏年

運作代碼:

方法一:

Private Sub Command1_Click()

   Dim myYear As Boolean

   If IsNumeric(Text1.Text) Then

       If Text1.Text Mod 400 = 0 Then

           myYear = True

       ElseIf Text1.Text Mod 4 = 0 And Text1.Text Mod 100 <> 0 Then

       Else

           myYear = False

       End If

       If myYear = True Then

           Picture1.Print Text1.Text & "是閏年!"

           Picture1.Print Text1.Text & "是平年!"

   Else

       Picture1.Print Text1.Text & "不是數字"

   End If

End Sub

方法二:

Public Function LeapYear(ByVal yea As Integer) As Boolean     '閏年函數

   If (yea Mod 4) = 0 Then

       LeapYear = (yea Mod 100 > 0) Or (yea Mod 400 = 0)

End Function

學習總結:

通用的步驟,可以使用函數,友善以後調用。

繼續閱讀