Thanks to @Kem Tekinay and @MarkusR, I know what I’m doing: putting both classes in a module. But, I’m still very confused and maybe somebody can help me better understand.
I have spent a couple hours now researching Modules vs Classes. Modules appear to be for global variables and objects that you reference throughout a program. What I’m trying to do is specify an object that implements a state machine. That sounds like a Class. So I create Class StateMachine and place it in a Module:
Module SomeName
(other globals, if I need them)
Public Class StateMachine
(code)
End Class
End Module
Now, in Class StateMachine I would like a data structure StateDescriptor to hold the information for each state. It will only be used in Class StateMachine. In C, I would use a struct. I like the idea of using a class instead, it seems much more flexible. It allows things like having code associated with the StateDescriptor for bounds checking, etc. If it were a struct, I’d place it in Class StateMachine. Xojo has a data structure like struct and that is Structure. But, the Language Reference says it’s not for this application but for memory organization to match APIs and so on and that a Class should be used instead. So, I add in Class StateDescriptor:
Module SomeName
(other globals, if I need them)
Public Class StateMachine
(constructor has dim state(10) As StateDescriptor)
(code)
End Class //StateMachine
Private Class StateDescriptor
nextStateOnButtonPush As Integer = 0
nextStateOnTimeout As Integer = 0
numSecondsToTimeout As Integer
output As Integer
End Class //StateDescriptor
End Module //SomeName
This is what I am doing. But, I am not-happy/confused because now I don’t have one object in the code that represents the state machine. The Module doesn’t really because I can’t instantiate a state machine module. Instead, I have to instantiate the state machine class from the SomeName module.
I guess what I really think is needed it a Class within a Class. I just searched the forum for this and found it was already discussed and it’s not part of the language. It’s a shame. I’ve fallen in love with the logical structure of Xojo and this is like a missing bone from the little finger of the language. But, from reading the forum, I also understand limited resources. So, I apply a splint.
But, unfortunately I have the personality trait that whenever I look at the language as a whole, I’m going to keep noticing that little splint down on the little finger.