# How to define a module global variable

**URL:** <https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760>\
**Category:** Getting Started\
**Created:** [January 1, 2025, 8:06pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760 "2025-01-01T20:06:07Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Watson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@David\_Watson](https://forum.xojo.com/u/David_Watson)\
**Post date:** [January 1, 2025, 8:06pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/1 "2025-01-01T20:06:07Z")

</div>

I’m lost on how to add a global variable to a method. I’m not using classes or properties. Coming from a VB6 background I’m used to having a module and placing code at the module level. Not within a procedure within the module. After creating a module, I can’t add code to it. I have to create a method to do that.

For example, I want to define these arrays at a window module level and allow access to any code within the window module. For a control on the window, any of the control events should be able to use the window level variable.

Var m1(1,1) As Integer  
Var m2(1,1) As Integer  
Var ResultMatrix(1,1) As Integer

---

<div class="post-metadata">

**Author:** ![MarkusR](https://forum.xojo.com/user_avatar/forum.xojo.com/markusr/32/685_2.png) [@MarkusR](https://forum.xojo.com/u/MarkusR)\
**Post date:** [January 1, 2025, 8:14pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/2 "2025-01-01T20:14:09Z")

</div>

Its named propertie in Xojo.

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [January 1, 2025, 8:14pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/3 "2025-01-01T20:14:13Z")

</div>

There’s no such thing as a “Window Module” in Xojo. If you add a module to a Xojo _project_, any methods, constants or properties in the module whose Scope is set to “Global” are available to code anywhere in the app.

Any properties, methods, or constants added to a Window via the IDE are accessible to any code in that window. They can be accessed by other objects in the app if their scope is set to Public.

Any properties or constants declared within a method in a window are only accessible within that method.

---

<div class="post-metadata">

**Author:** ![Jerry\_Fritschle](https://forum.xojo.com/user_avatar/forum.xojo.com/jerry_fritschle/32/223_2.png) [@Jerry\_Fritschle](https://forum.xojo.com/u/Jerry_Fritschle)\
**Post date:** [January 1, 2025, 8:22pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/4 "2025-01-01T20:22:03Z")

</div>

> [@Julia\_Truchsess](#):
>
> If you add a module to a Xojo _project_, any methods, constants or properties in the module whose Scope is set to “Global” are available to code anywhere in the app.

This works great, but I use it sparingly. The longer I’ve been at this, the more I have drifted toward the “Global Variables are Evil!®” school. 🙂

---

<div class="post-metadata">

**Author:** ![David\_Watson](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/e68b1a/32.png) [@David\_Watson](https://forum.xojo.com/u/David_Watson)\
**Post date:** [January 1, 2025, 8:34pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/5 "2025-01-01T20:34:58Z")

</div>

Did not know that module variables are called properties.  
I added a property, but I don’t see how to make the property a multi dimensional array. If I use (,) for type, xojo changes it (

---

<div class="post-metadata">

**Author:** ![Julia\_Truchsess](https://forum.xojo.com/user_avatar/forum.xojo.com/julia_truchsess/32/499_2.png) [@Julia\_Truchsess](https://forum.xojo.com/u/Julia_Truchsess)\
**Post date:** [January 1, 2025, 8:42pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/6 "2025-01-01T20:42:23Z")

</div>

> [@David\_Watson](#):
>
> I don’t see how to make the property a multi dimensional array.

 ![image](https://forum.xojo.com/uploads/default/original/3X/8/7/87991626d243226dfb0f063106914b92e3ce67e0.png)

You can use whatever dimensions you want in the Inspector definition, and you can redimension the array later with

`ReDim Foo(10,10)`

later if needed. Note you cannot _append_ values to a multi-dimensional array like you can with a 1-dimensional array - the dimensions are fixed unless you re-dim. For this reason I almost never use multidimensional arrays, I use classes having 1-dimensional arrays as class properties.

---

<div class="post-metadata">

**Author:** ![Tim\_Hare](https://forum.xojo.com/user_avatar/forum.xojo.com/tim_hare/32/176_2.png) [@Tim\_Hare](https://forum.xojo.com/u/Tim_Hare)\
**Post date:** [January 1, 2025, 9:50pm UTC](https://forum.xojo.com/t/how-to-define-a-module-global-variable/83760/7 "2025-01-01T21:50:24Z")

</div>

Put the dimensions in the Name field, eg., m1(1,1). The Type is simply Integer.
