Building a Calculator
Learning to use REALbasic Modules within a project
Issue: 2.3 (December/January 2003)
Author: Thomas J. Cunningham
Author Bio: Thomas is a hobbyist programmer who enjoys sharing the RB loving with others. His online RB Beginner tutorial has had over 20,000 hits!
Article Description: No description available.
Article Length (in bytes): 9,821
Starting Page Number: 28
Article Number: 2312
2312.zip Updated: 2013-03-11 19:07:57
Related Link(s): None
Excerpt of article text...
This month we will learn to use a Module in a project. A Module is a unique and valuable construct in RB. It is an area of our program where we can store things that are "global" to our program. The term "global" in RB can be a bit confusing and needs to be qualified since a Window or Application Class property can also be termed global.
In a window, we can declare properties that are global. However, there are a few subtleties here. If another object or class wants to refer to this window property, you have to use dot notation to get to it. For example, a property declared on MainWindow called
mNameis referred to by calling
mNameis declared as Protected, only objects in the MainWindow may refer to the property. Another window may not access this private property directly. The same principle can be applied to an Application class.
A Module is similar to a class, but it is not a class. A Module does not need to be instantiated by your project -- once it is added to your project, it always exists. A Module can store three global items: Constants, Methods, and Properties. It has no Events. Note that one of the more useful ways a Module is used -- which I will not discuss here -- is the localization of your program to different languages.
The Constants area is unique to a Module in RB. These Constants can be assigned any of five different data types: integer, double, string, Boolean or color. Using Constants is a very common and useful technique in programming. For example, let's say you're writing a program that does a lot of drawing. You find yourself using a special green color and you're tired of re-coding this over and over as
RGB(28,107,51). No problem, a color Constant comes to the rescue. You create a Module, declare a color Constant as
myGreenColorand assign its value once. Now all you have to do is refer to
myGreenColoranywhere in your program. Referring to your new Constant is far more intuitive.
A Calculator Example
...End of Excerpt. Please purchase the magazine to read the full article.