Modules vs Classes | ||
They have the same shape in the project window and they have some other things in common too so what are the important differences between modules and classes? And how do I know which one to use? | ||
![]() | ||||
Classes are green, | ||||
If we double click on Module1 and Class1 we see that they have some differences in the list of items in their respective code editors. | ||
Module | Class | |||
![]() | ||||
![]() | ||||
Both the Module and the Class have Methods, Notes, and Properties in their lists. The Module has an item, "Constants", which the Class does not have. The Class has "Events, Menu Handlers, and New Events" which the Module is lacking. | ||
If you compare the list in a Window's code editor to the list in the Class' code Editor you will see that they are very similar. This is because a window is, in fact, a class. Classes, like Windows, can respond to Events. A user can interact with a class. For example, in the topic "Custom Classes" we made a custom class that a user could click to open a URL. Users cannot interact directly with a module. Modules store global data. Constants, Methods and Properties in a module can be accessed by any object anywhere in the project at any time. | ||
Understanding the difference between Modules and Classes is a matter of understanding their respective functions. The function of a Module is to store global data. The Methods and Properties of classes are local to the object that contains them, such as a window or a custom class. The function of a Class is to provide a means for users to give input to or receive output from a program. All controls such as PushButtons, Listboxes, Editfields, etc. are classes. | ||
A Class is added to a project when the programmer wants to create an object with which a user can interact, such as the clickable StaticText object discussed in the topic "Custom Classes". A Module is added to a project when the programmer wants to employ global properties, methods, or constants. | ||