vb.net数组结构——枚举类型

 时间:2026-02-14 10:57:58

1、Record a DayAction of one of the following possible values:

Asleep

Getting ready for work

Traveling to work

At work

At lunch

Traveling from work

Relaxing with friends

Getting ready for bed

vb.net数组结构——枚举类型

2、Public Class Form1

   '定义枚举类型

    'DayAction Enumeration

    Private Enum DayAction As Integer

        Asleep = 0

        GettingReadyForWork = 1

        TravelingToWork = 2

        AtWork = 3

        AtLunch = 4

        TravelingFromWork = 5

        RelaxingWithFriends = 6

        GettingReadyForBed = 7

    End Enum

vb.net数组结构——枚举类型

3、'Declare variable

Private CurrentState As DayAction

Add the following code below the variable you just added:

'Hour property

Private Property Hour() As Integer

    Get

        'Return the current hour displayed

        Return dtpHour.Value.Hour

    End Get

    Set(value As Integer)

        'Set the date using the hour passed to this property

        dtpHour.Value =

            New Date(Now.Year, Now.Month, Now.Day, value, 0, 0)

        'Set the display text

        lblState.Text = "At " & value & ":00, Richard is "

    End Set

End Property

vb.net数组结构——枚举类型

vb.net数组结构——枚举类型

4、Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load

    'Set the Hour property to the current hour

    Me.Hour = Now.Hour

End Sub

vb.net数组结构——枚举类型

5、Private Sub dtpHour_ValueChanged(sender As Object,

            e As EventArgs) Handles dtpHour.ValueChanged

    'Update the Hour property

    Me.Hour = dtpHour.Value.Hour

End Sub

vb.net数组结构——枚举类型

6、执行结果入戏图所示:

vb.net数组结构——枚举类型

1、Set(value As Integer)

    'Set the date using the hour passed to this property

    dtpHour.Value =

        New Date(Now.Year, Now.Month, Now.Day, value, 0, 0)

    'Determine the state

    If value >= 6 And value < 7 Then

        CurrentState = DayAction.GettingReadyForWork

    ElseIf value >= 7 And value < 8 Then

        CurrentState = DayAction.TravelingToWork

    ElseIf value >= 8 And value < 13 Then

        CurrentState = DayAction.AtWork

    ElseIf value >= 13 And value < 14 Then

        CurrentState = DayAction.AtLunch

    ElseIf value >= 14 And value < 17 Then

        CurrentState = DayAction.AtWork

    ElseIf value >= 17 And value < 18 Then

        CurrentState = DayAction.TravelingFromWork

    ElseIf value >= 18 And value < 22 Then

        CurrentState = DayAction.RelaxingWithFriends

    ElseIf value >= 22 And value < 23 Then

        CurrentState = DayAction.GettingReadyForBed

    Else

        CurrentState = DayAction.Asleep

    End If

    'Set the display text

    lblState.Text = "At " & value & ":00, Richard is " &

        CurrentState

End Set

vb.net数组结构——枚举类型

2、'Set the display text

    lblState.Text = "At " & value & ":00, Richard is " &

        CurrentState.ToString()

End Set

vb.net数组结构——枚举类型

  • 逆水寒采木头攻略
  • 逆水寒梅鹤方盒怎么打开钥匙怎么获得方法
  • VB6.0找出若干个数中最大的数
  • 天命奇御神器碎片怎么刷
  • 逆水寒英雄仗剑行攻略
  • 热门搜索
    乌龟怎么养 殇怎么读拼音 怎么给电脑设置开机密码 颜色用英语怎么说 李毅吧为什么这么火 学习计划怎么写 腌黄瓜咸菜的做法 闫怎么读 为什么月经会推迟 怎么养胃