Accessing Enumeration of App

I have an interesting issue I’m running into. I have a public enumeration of App, and I’m trying to access it from Session. The problem is, the compiler won’t seem to allow me to do this as I get a “This item does not exist” error where I access it. I know that in normal OOP circumstances an enumeration would be accessed in ClassName.Enumeration form, as the enumeration isn’t a property, but a constant of sorts. The problem is, App is a special circumstance, so I have nothing more than App to use.

My code looks something like this:

Select Case App.EnumProperty Case App.MyEnum.Value // Do something End Select

Thanks!

For better or worse, the language allows for many things to share the same name. In this case, what you’re running into is that there is actually a global function called ‘App’ that returns the global instance of the ‘App’ class.

Given that, what your code is actually doing is this:

Select Case App().EnumProperty Case App().MyEnum.Value // Do something End Select

This results in a compile error because the ‘MyEnum’ enumeration is on the ‘App’ class and not the instance returned from ‘App()’. My recommendation is to rename your ‘App’ class to anything else.

1 Like

This particular item has caused NO end of confusion over the years

Oh… That is strange. So if I were to rename it to “MainApp”, then MainApp would be the class, and App the instance? In which case, if I’m accessing App quite a bit from a single method, would the following be recommended?

Dim App As MainApp = App

[quote=9980:@Jason Adams]Oh… That is strange. So if I were to rename it to “MainApp”, then MainApp would be the class, and App the instance? In which case, if I’m accessing App quite a bit from a single method, would the following be recommended?

Dim App As MainApp = App

Doing this wouldn’t get you much. The performance cost of App() is very low and the local variable would just introduce a new bit of confusion.

As for your original code, you can rewrite it as so:

Select Case App.EnumProperty Case MyApp.MyEnum.Value // Do something End Select

Gotcha, I just wasn’t sure if it was advised to do it similar to the fabled:

Dim Session As Session = Session

But I suppose this would have more overhead as it’s actually sifting between multiple instances, wherein there’s only ever one instance of App running.

Got it working though, thanks!

I encountered the enum problem and after some Google searching found this page. Had i not found it, it would have meant a call into support. Thank you all for posting this.