Operator_Subscript and shared class methods

I’m trying to write a drop-in replacement for the Screen() class, implementing it as a class called cScreen which has shared methods such as Count.

To make it easy to use, I want to be able to replace

 dim s as Screen = Screen(N) 


 dim s as cScreen = cScreen(N) 

To accomplish this, I’ve added this to my cScreen class:

Public Shared Function Operator_Subscript(index as integer) as cScreen
  return mScreens(index)
End Function

But when I compile, I get this error:

 dim s as cScreen = cScreen(N)  // Type Mismatch error: Expected class cScreen but got Integer

It appears the compiler is seeing “cScreen(N)” as a cast, not as Operator_Subscript.

I’m using Xojo 2019R1.1

pretty sure that the operator_XXX methods only work on instances not class types like youre trying to create
HOWEVER what you want to do is possible its just not organized as JUST a class :slight_smile:
try this organization

Module cScreen
       Global Class cScreen
       End Class

       Global Function cScreen(index as integer) as cScreen
       end function
End module