Global Enumeration

I have a Window that has an Enumeration: say enContext. It is commonly addressed and changed within the Window and exclusively “used” within the Window. But occasionally I want to be able to change its value elsewhere.

That Window comes in and out of existence during the use of the application.

Let’s say I want to maintain a Global value that is available to change in other parts of the application with other Windows open. If I return to the Window with the Enumeration, and I want to use the Global value to select a particular enContext value, what is the best way to do this?

I can imagine pulling the Enumeration outside of the Window entirely into a Module so it itself is Global but I resist this, perhaps stupidly. Perhaps I can use an Integer as a Global value that “matches” one of the Window’s enumeration values, but then it seems that using an Enumeration at all loses some of its value (Integers can take on any value outside the range of the Enumeration itself.)

Do any people more experienced with using Enumerations have a suggestion of how to handle this elegantly? What approach would they take?

You could use a Shared computed property on your window class. Then it wouldn’t matter if an instance of the window currently exists. Essentially the same as storing it in a module, but you maintain logical encapsulation.

Window Window1
Inherits DesktopWindow
  Public Enum ValueNumber
      ValueOne
      ValueTwo
  End Enum

  Private Shared Property mEnumValue As ValueNumber

  Public Shared Property EnumValue As ValueNumber
  Get
    Return mEnumValue
  End Get

  Set
    mEnumValue = value
  End Set

  End Property

End Window
2 Likes

Didn’t finish my thought. Then you can access it anywhere like:

Window1.EnumValue = Window1.ValueNumber.ValueTwo

With Implicit Instance disabled and without an instance of Window1.