I have an Enum thus:
Enum CurrentPeriodType
CurrentDate
Sales
Utilization
End Enum
I have a function thus:
Private Sub PopulateDDLPeriods(currentPeriodType As CurrentPeriodType)
...
End Sub
I make a function call thus:
PopulateDDLPeriods(False)
I run it, it compiles and runs, and I step through the code and indeed it is going from the function call into the function that expects an ENUM. I thought maybe I had an overload…but I actually stepped through the code and it went into the ENUM parameter-typed function…
HUH?
This is only possible because your
Option Strictis off. If you do not like the behavior that you see, turn it on. However, doing so will also implyOption Explicitforcing you to declare all variables, and also to specify the data type of yourEnumwhich is how we knew you had it off.In your case, the internal value of
CurrentDateis0. It is therefore not very surprising (considering thatOption Strictis off) thatFalsecan convert to 0 and also to the enum.What could be more surprising is that your code will compile and run even after you change it as follows:
or alternatively, if you start passing in
True(which converts to -1).As you can see, .NET enums are just “partly enumerated” synonyms for their respective underlying data types and you can get in any value of such a data type if you try just a little.