Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 2.3

COLUMN

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
Resource File(s):

Download Icon 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 mName is referred to by calling MainWindow.mName. If mName is 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 myGreenColor and assign its value once. Now all you have to do is refer to myGreenColor anywhere 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.