How to make an array or dictionary available to multiple methods

I think I’m going crazy.

Surely there is a way to create an array or dictionary that is independent of a method - a Property() for instance?

I did create a Property(x, x) As Double, which complied OK and didn’t crash unless I cause an out of bounds error (So Xojo must think it’s a thing) but damned If I can populate it in a way that returns anything.

What am I missing?

Everything that is located in a Module is global to the app. Create you dictionary in a Module.

Hard to say because it definitely is a thing.

When you define an array, you can just use it within the same scope it was defined. That means, for example, a Global property in a Module can be accessed from anywhere (see Gilles’s post above), and a private property within a class can be accessed by that instance of the class.

Perhaps you can calling var or dim again to create a shadow property within your method? If so, remove that.

Perhaps you aren’t initializing a Dictionary property? When you create the property, it is merely a placeholder, much like calling var d as Dictionary in your method. It remains Nil until you create a new instance of the object somewhere.

Or perhaps it’s something else, without seeing your code it’s difficult to advise you.

Might be a shadow property. This is a problem where you have to bang you head on the desk until you see the problem.

Happens to all of us.

Thanks all. Good to know I’m on the right track.

Checked for shadow properties but nothing.

I am a bear of very little brain so I guess I’ll head back to the old docs to see how it’s done. The new ones address arrays and properties but not the combination thereof.

Did you actually CALL it Property?
Property is a reserved word… doesnt compile for me…

Try adding a (new) named, public property to the App

Then initialising it in the App’s Open event:

Then use it in any window:

msgbox format(app.mymap(3,5),"0")

Thanks everyone. Sorted! I was attempting to populate the array from within the property, as default settings, just as you do with a normal property.

Because you all so kindly pointed out that properties as arrays are a thing :-), I stopped thinking about it as a property but as an array. Working a dream. Thank you. That’s about a page of code less to compile!