📄 ctime2.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "CTime2"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
' Fig. 16.4
' Class definition for CTime2
' This class enhances CTime1 by providing Property procedures
' for Hour, Minute and Second properties
Option Explicit
Private mHour As Integer
Private mMinute As Integer
Private mSecond As Integer
Public Sub SetTime(ByVal h As Integer, ByVal m As Integer, _
ByVal s As Integer)
mHour = ValidateHour(h)
mMinute = ValidateMinute(m)
mSecond = ValidateSecond(s)
End Sub
Public Function ToUniversalTime() As String
ToUniversalTime = Format$(mHour, "00") & ":" & _
Format$(mMinute, "00") & ":" & _
Format$(mSecond, "00")
End Function
Public Function ToStandardTime() As String
Dim h As Integer
h = IIf((mHour = 12 Or mHour = 0), 12, mHour Mod 12)
ToStandardTime = h & ":" & _
Format$(mMinute, "00") & ":" & _
Format$(mSecond, "00") & " " & _
IIf(mHour < 12, "AM", "PM")
End Function
Public Property Get Hour() As Integer
Hour = mHour
End Property
Public Property Let Hour(ByVal h As Integer)
mHour = ValidateHour(h)
End Property
Public Property Get Minute() As Integer
Minute = mMinute
End Property
Public Property Let Minute(ByVal m As Integer)
mMinute = ValidateMinute(m)
End Property
Public Property Get Second() As Integer
Second = mSecond
End Property
Public Property Let Second(ByVal s As Integer)
mSecond = ValidateSecond(s)
End Property
Private Function ValidateHour(ByVal h As Integer)
ValidateHour = IIf((h >= 0 And h < 24), h, 0)
End Function
Private Function ValidateMinute(ByVal m As Integer)
ValidateMinute = IIf((m >= 0 And m < 60), m, 0)
End Function
Private Function ValidateSecond(ByVal s As Integer)
ValidateSecond = IIf((s >= 0 And s < 60), s, 0)
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -