📄 minimal.vb
字号:
Public Class Minimal
Public Enum AgeGroup
Baby
Toddler
Teenager
Adult
Senior
Overaged
End Enum
Public property1 As String, property2 As Double
Private tAge As Integer
Property Age() As Integer
Get
Age = tAge
End Get
Set(ByVal Value As Integer)
If Value < 0 Or Value > 125 Then
Dim AgeException As New ArgumentException()
Throw AgeException
Else
tAge = Value
End If
End Set
End Property
Private tBDate As Date
Property BDate() As Date
Get
BDate = tBDate
End Get
Set(ByVal Value As Date)
If Value > Now() Or DateDiff(DateInterval.Year, Now(), Value) > 125 Then
MsgBox("Age must be positive and less than 125")
Else
tBDate = Value
tAge = DateDiff(DateInterval.Year, Now(), Value)
End If
End Set
End Property
Public Function ReverseString() As String
Return (StrReverse(property1))
End Function
Public Function NegateNumber() As Double
Return (-property2)
End Function
Public Function CountWords(ByVal aString As String) As Integer
While InStr(aString, " ") > 0
aString = Replace(aString, " ", " ")
End While
Dim words As Integer = 1, spaceLoc As Integer = 0
spaceLoc = InStr(aString, " ")
While spaceLoc > 0
words = words + 1
spaceLoc = InStr(spaceLoc + 1, aString, " ")
End While
Return (words)
End Function
Public Function GetAgeGroup() As AgeGroup
Dim group As AgeGroup
Select Case tAge
Case Is < 5 : Return (group.Baby)
Case Is < 12 : Return (group.Toddler)
Case Is < 21 : Return (group.Teenager)
Case Is < 65 : Return (group.Adult)
Case Is < 100 : Return (group.Senior)
Case Else : Return (group.Overaged)
End Select
End Function
Public Sub New()
tmr = New System.Timers.Timer()
tmr.Interval = 10000
tmr.Enabled = True
End Sub
Shared LoggedUsers As Integer
ReadOnly Property Users() As Integer
Get
Users = LoggedUsers
End Get
End Property
Public Function Connect() As Integer
LoggedUsers = LoggedUsers + 1
End Function
Public Function Disconnect() As Integer
If LoggedUsers > 1 Then
LoggedUsers = LoggedUsers - 1
End If
End Function
Public Overrides Function ToString() As String
Return ("MINIMAL: " & tBDate.ToString)
End Function
Public Overloads Function Equals(ByVal obj As Object) As Boolean
Dim O As New Minimal()
Try
O = CType(obj, Minimal)
Catch typeExc As InvalidCastException
Throw typeExc
Exit Function
End Try
If O.BDate = tBDate Then
Equals = True
Else
Equals = False
End If
End Function
Dim WithEvents tmr As System.Timers.Timer
Public Event TeaTime(ByVal sender As Object)
Private Sub tmr_Elapsed(ByVal sender As Object, _
ByVal e As System.Timers.ElapsedEventArgs) Handles tmr.Elapsed
Console.WriteLine(DateDiff(DateInterval.Second, Now(), _
DateAdd(DateInterval.Hour, 17, System.DateTime.Today)))
If DateDiff(DateInterval.Second, Now(), _
DateAdd(DateInterval.Hour, 17, System.DateTime.Today)) < 10500 Then
tmr.Enabled = False
RaiseEvent TeaTime(Me)
End If
End Sub
End Class
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -