Global Variables

Xojo Version 2021 r3.1

Variable Scope:

The scope of a variable refers to what part of the program a variable and its value can be used.

  • Local variables - only declared and used in procedure or function they are created in
  • Global variables - declared after the public class statement or within a module and available to all functions procedures in the code.

To create global variables in XOJO we must use with the XOJO GUI. Global variables/modules are not created directly in code.

Modules in XOJO:

A module is a collection of project items, usually containing methods/functions, properties, and constants. Once created they always exist within a project.

  • Modules contain properties that act as our variables.
  • A property is a variable that belongs to a class or module.

Create a Module in XOJO:

  • Go to the menu bar click Insert
  • Select Module from the drop-down menu
  • Name the module
  • Do not include spaces in the module name!

Add a Property to the Module:

  • Select the module in the navigator
  • Click on Insert from the Menu Bar
  • Select Property
    • On the right side:
    • Give it a name
    • Give it a type (integer, double, string)
    • Set default value
    • Set scope to global