Guest User

Enumeration

a guest
Jan 31st, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class Form1
  2.     'DayAction Enumeration
  3.    Private Enum DayAction As Integer
  4.         Asleep = 0
  5.         GettingReadyForWork = 1
  6.         TravelingToWork = 2
  7.         AtWork = 3
  8.         AtLunch = 4
  9.         TravelingFromWork = 5
  10.         RelaxingWithFriends = 6
  11.         GettingReadyForBed = 7
  12.     End Enum
  13.  
  14.     'Declare Variable
  15.    Private CurrentState As DayAction
  16.  
  17.     'Hour property
  18.    Private Property Hour() As Integer
  19.         Get
  20.             'Return the current hour displayed
  21.            Return dtpHour.Value.Hour
  22.         End Get
  23.         Set(value As Integer)
  24.  
  25.             'Set the date using the hour passed to this property
  26.            dtpHour.Value = New Date(Now.Year, Now.Month, Now.Day, value, 0, 0)
  27.  
  28.             'Determin the state
  29.            If value >= 6 And value < 7 Then
  30.                 CurrentState = DayAction.GettingReadyForWork
  31.             ElseIf value >= 7 And value < 8 Then
  32.                 CurrentState = DayAction.TravelingFromWork
  33.             ElseIf value >= 8 And value < 13 Then
  34.                 CurrentState = DayAction.AtWork
  35.             ElseIf value >= 13 And value < 14 Then
  36.                 CurrentState = DayAction.AtLunch
  37.             ElseIf value >= 14 And value < 17 Then
  38.                 CurrentState = DayAction.AtWork
  39.             ElseIf value >= 17 And value < 18 Then
  40.                 CurrentState = DayAction.TravelingFromWork
  41.             ElseIf value >= 18 And value < 22 Then
  42.                 CurrentState = DayAction.RelaxingWithFriends
  43.             ElseIf value >= 22 And value < 23 Then
  44.                 CurrentState = DayAction.GettingReadyForBed
  45.             Else
  46.                 CurrentState = DayAction.Asleep
  47.             End If
  48.  
  49.             'Set the display text
  50.            lblState.Text = "At " & value & ":00, Richard is " & CurrentState.ToString
  51.         End Set
  52.     End Property
  53.  
  54.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
  55.         'Set the hour to the current hour
  56.        Me.Hour = Now.Hour
  57.     End Sub
  58.  
  59.     Private Sub dtpHour_ValueChanged(sender As Object, e As EventArgs) Handles dtpHour.ValueChanged
  60.         'Update the hour property
  61.        Me.Hour = dtpHour.Value.Hour
  62.     End Sub
  63. End Class
Advertisement
Add Comment
Please, Sign In to add comment