From the course: Visual Basic Essential Training

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Work with enum values

Work with enum values

- [Instructor] We've heard about classes and modules earlier in this course. Another type we can create is the Enum type. Enums allow us to create a group of related constants under a single name. Think of Enums as a way to make our code more descriptive and easier to maintain. Because they are a type, not a simple constant, we can use the Enum type as our variable type. On line 53, I'm declaring the current day variable as the day of the week type, which is a .NET library type. So then, on line 54, when I'm writing my code, I get a list of the possible Enum values. Even better, when I turn Option Strict on, the compiler ensures that only Enum values are assigned to that variable, so there is no possibility of a runtime error. I'm working with some of the Enums that are part of .NET, starting with the day of the week, which we saw on the slides. Here, I'm declaring a variable called Dim currentDay. I specify the Enum type DayOfWeek, and then here I'm assigning one of the enumeration…

Contents