Immediate Window bug with Enumeration

Perhaps I am mis-using Enum  It works at run-time though so maybe I should just ignore the immediate window...
The problem is illustrated below:

Try putting this code in a new Windows form project (in the default form1 class)


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim intx As Integer = MyFunction(Me.MyDay)
    End Sub

    Private Function MyFunction(ByVal Day As Days) As Integer
        Select Case Day

            Case Days.Monday
                Return 1
            Case Else
                Return Day
        End Select
    End Function

    Enum Days
        Sunday = 1
        Monday = 2
        Tuesday = 3
        Wednesday = 4
        Thurday = 5
        Friday = 6
        Saturday = 7
    End Enum

    Private mDay As Days = Days.Monday 'Default to a Monday
    Public Property MyDay() As Days
        Get
            Return mDay
        End Get
        Set(ByVal DAY As Days)
            mDay = DAY
        End Set
    End Property


Put a Breakpoint on the form load event. If you step though the code intx becomes 1 as expected (as the Property is set to Monday).

However if you do the following in the immediate window while at a*space
space*point you get:
MyFunction(Me.MyDay)
84355960


MyFunction(Me.MyDay)
84355972

Each time you do it the number increases by 12  Is 12 a magic number !!!! Does 84 million have some sort of significance.



Answer this question

Immediate Window bug with Enumeration

  • Immediate Window bug with Enumeration