- 最後登錄
- 2024-11-2
- 在線時間
- 7253 小時
- 註冊時間
- 2010-5-4
- 閱讀權限
- 95
- 精華
- 0
- UID
- 7964333
- 帖子
- 155
- 積分
- 1282 點
- 潛水值
- 47965 米
| 如果你忘記伊莉的密碼,請在登入時按右邊出現的 '找回密碼'。輸入相關資料後送出,系統就會把密碼寄到你的E-Mail。 本帖最後由 tryit244178 於 2020-5-5 12:40 AM 編輯
閒著沒事,來點別的寫法- Public Class Form1
- Private microSecond As New Limit(10), milliSecond As New Limit(10)
- Private sec As New Limit(60), min As New Limit(60)
- Private carry10 As New Carrier(10)
- Private carry60 As New Carrier(60)
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- milliSecond = 0
- microSecond = 0
- sec = 0
- min = 0
- End Sub
- Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
- Timer1.Enabled = Not Timer1.Enabled
- End Sub
- Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
- milliSecond += 1
- carry10.CheckCarry(microSecond, milliSecond)
- carry10.CheckCarry(sec, microSecond)
- carry60.CheckCarry(min, sec)
- Label1.Text = CUInt(min) & "分:" & CUInt(sec) & "秒:" & CUInt(microSecond) & CUInt(milliSecond)
- End Sub
- End Class
- Public Class Carrier
- Private _carry As UInteger
- Public Sub New(ByVal carry As UInteger)
- _carry = carry
- End Sub
- Public Sub CheckCarry(ByRef highOrder As Limit, ByRef lowOrder As Limit)
- If CUInt(lowOrder) = _carry Then
- lowOrder = 0
- highOrder += 1
- End If
- End Sub
- End Class
- Public Structure Limit
- Private Shared _min As UInteger
- Private Shared _max As UInteger
- Private _value As UInteger
- Public Sub New(ByVal Max As UInteger)
- _min = 0
- _max = Max
- End Sub
- Public Sub New(ByVal Min As UInteger, ByVal Max As UInteger)
- _min = Min
- _max = Max
- End Sub
- Public Shared Widening Operator CType(ByVal l As Limit) As UInteger
- Return l._value
- End Operator
- Public Shared Narrowing Operator CType(ByVal value As UInteger) As Limit
- If value < _min Or value > _max Then
- 'Throw New ArgumentOutOfRangeException(value & "超出範圍")
- value = 0
- End If
- Dim result As New Limit(_min, _max)
- result._value = value
- Return result
- End Operator
- Public Shared Operator +(ByVal first As Limit, ByVal second As Limit) As Limit
- Dim result As New Limit(_min, _max)
- result = first._value + second._value
- Return result
- End Operator
- End Structure
複製代碼 ... |
|