Advertisement
bilde2910

Time Class release 1

Jun 8th, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.55 KB | None | 0 0
  1. ' Time class for counting hours, minutes and seconds.
  2. ' by bilde2910
  3.  
  4. ' Version 1
  5. ' For a list of versions, see http://bit.ly/timeclass
  6.  
  7. Public Class Time
  8.     Public Shared Hour As Byte
  9.     Public Shared Minute As Byte
  10.     Public Shared Second As Byte
  11.  
  12.     Public Sub AddHours(ByVal Hours As Byte)
  13.         If Hours > 23 Then
  14.             Throw New ArgumentException("The value is too high.", "Hours")
  15.         Else
  16.             Hour += Hours
  17.             If Hours > 23 Then Throw New ArgumentException("The time is more than 23 hours, 59 minutes and 59 seconds.", "Hours")
  18.         End If
  19.     End Sub
  20.     Public Sub AddMinutes(ByVal Minutes As Integer)
  21.         Minute += Minutes
  22.         Do While Minute > 59
  23.             AddHours(1)
  24.             Minute -= 60
  25.         Loop
  26.     End Sub
  27.     Public Sub AddSeconds(ByVal Seconds As Integer)
  28.         Second += Seconds
  29.         Do While Second > 59
  30.             AddMinutes(1)
  31.             Second -= 60
  32.         Loop
  33.     End Sub
  34.     Public Shadows Function ToString(ByVal format As String)
  35.         Dim time As String = format
  36.         time = Replace(time, "HH", IIf(Hour < 10, "0" & Hour, Hour))
  37.         time = Replace(time, "H", Hour)
  38.         time = Replace(time, "mm", IIf(Minute < 10, "0" & Minute, Minute))
  39.         time = Replace(time, "m", Minute)
  40.         time = Replace(time, "ss", IIf(Second < 10, "0" & Second, Second))
  41.         time = Replace(time, "s", Second)
  42.         Return time
  43.     End Function
  44.  
  45.     Public Sub New()
  46.         Hour = 0
  47.         Minute = 0
  48.         Second = 0
  49.     End Sub
  50. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement