none
尋求程式的註解 RRS feed

  • 一般討論

  • 粗體字的部分我看不懂可以幫我註解意思嗎?Public Class Form1
        Dim date1 As New CCDate

        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            output.Text = date1.getdate()
        End Sub

        Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
            output.Text = date1.getdate("TAIWAN")
        End Sub

        Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
            date1.setdate(CInt(year.Text), CInt(month.Text), CInt(day.Text))
        End Sub
    End Class
    Class CCDate
        Private _year As Integer '宣告_year整數變數
        Private _month As Integer  '宣告_month整數變數
        Private _day As Integer '宣告_day整數變數

        Public Property year() As Integer
            Get
                Return (_year)
            End Get
            Set(ByVal value As Integer)
                _year = value
            End Set
        End Property

        Public Property month() As Integer
            Get
                Return (_month)
            End Get
            Set(ByVal value As Integer)
                If value > 12 Then '如果value大於12
                    MsgBox("月份應填入1-12") '提示月份應填入1-12訊息
                    value = 12
                End If
                _month = value
            End Set
        End Property
        Public Property day() As Integer
            Get
                Return (_day)
            End Get
            Set(ByVal value As Integer)
                Dim dayPerMonth() As Integer = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} '宣告dayPerMonth()整數變數為{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
                If (month = 2) Then
                    If (year Mod 4 = 0 And year Mod 100 <> 0 Or year Mod 400 = 0) Then
                        If (value > 29) Then  '如果value大於29
                            MsgBox("日期有誤")  '提示日期有誤
                            value = 29  'value等於29
                        End If
                    Else '否則
                        If (value > 28) Then '如果value大於28
                            MsgBox("日期有誤") '提示日期有誤
                            value = 28 'value等於28
                        End If
                    End If
                Else '否則
                    If (value > dayPerMonth(month)) Then
                        MsgBox("日期有誤") '提示日期有誤
                        value = dayPerMonth(month)
                    End If
                End If
                _day = value
            End Set
        End Property

        Public Sub setdate(ByVal y As Integer, ByVal m As Integer, ByVal d As Integer)
            year = y
            month = m
            day = d
        End Sub

        Public Function getdate() As String
            Return CStr(year) + "/" + CStr(month) + "/" + CStr(day)
        End Function

        Public Function getdate(ByVal format As String) As String
            Dim r As String = "" '宣告r為字串變數
            If format = "TAIWAN" Then '如果format=TAIWAM
                r = "民國" + CStr(year - 1911) + "年" + CStr(month) + "月" + CStr(day) + "日"
            Else
                r = getdate()
            End If
            Return r
        End Function
        Public Sub New()
            year = 1990
            month = 1
            day = 1
        End Sub
    End Class
    2012年11月3日 上午 05:08

所有回覆