Enums Improve Readability

An enumerated type is simply a list of constants, each of which has a unique value. An Enum can improve the readability of your code by allowing you to declare a variable of your enumerated type, then assign one of the elements of the Enum to the value of the variable. Visual Basic makes this easy by providing you with a list of values for your variable as you use it:

 Public Enum TimeOfDay	Morning = 0	Afternoon = 1	Evening = 2End EnumSub Main()	Dim RightNow As TimeOfDay	If Time >= #12:00:00 AM# And Time < #12:00:00 PM# Then		RightNow = Morning	ElseIf Time >= #12:00:00 PM# And Time < #6:00:00 PM# Then		RightNow = Afternoon	ElseIf Time >= #6:00:00 PM# Then		RightNow = Evening	End IfEnd Sub

Validity checking is not done when assigning values to the special-typed variable. Even though the TimeOfDay values range from zero to two, VB doesn’t attempt to keep you from assigning a value of four, or another number, to such a variable. Be especially aware of this when writing Property Let procedures, which accept an enumerated parameter.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

iOS app development

The Future of iOS App Development: Trends to Watch

When it launched in 2008, the Apple App Store only had 500 apps available. By the first quarter of 2022, the store had about 2.18 million iOS-exclusive apps. Average monthly app releases for the platform reached 34,000 in the first half of 2022, indicating rapid growth in iOS app development.

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a