Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ' Time class for counting hours, minutes and seconds.
- ' by bilde2910
- ' Version 1
- ' For a list of versions, see http://bit.ly/timeclass
- Public Class Time
- Public Shared Hour As Byte
- Public Shared Minute As Byte
- Public Shared Second As Byte
- Public Sub AddHours(ByVal Hours As Byte)
- If Hours > 23 Then
- Throw New ArgumentException("The value is too high.", "Hours")
- Else
- Hour += Hours
- If Hours > 23 Then Throw New ArgumentException("The time is more than 23 hours, 59 minutes and 59 seconds.", "Hours")
- End If
- End Sub
- Public Sub AddMinutes(ByVal Minutes As Integer)
- Minute += Minutes
- Do While Minute > 59
- AddHours(1)
- Minute -= 60
- Loop
- End Sub
- Public Sub AddSeconds(ByVal Seconds As Integer)
- Second += Seconds
- Do While Second > 59
- AddMinutes(1)
- Second -= 60
- Loop
- End Sub
- Public Shadows Function ToString(ByVal format As String)
- Dim time As String = format
- time = Replace(time, "HH", IIf(Hour < 10, "0" & Hour, Hour))
- time = Replace(time, "H", Hour)
- time = Replace(time, "mm", IIf(Minute < 10, "0" & Minute, Minute))
- time = Replace(time, "m", Minute)
- time = Replace(time, "ss", IIf(Second < 10, "0" & Second, Second))
- time = Replace(time, "s", Second)
- Return time
- End Function
- Public Sub New()
- Hour = 0
- Minute = 0
- Second = 0
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement