global Array?

How to make an Array global?
I added a new Property and in inspector I put “Integer()” for the type. That creates a Syntax Error.

Module MyModule Global Function MyArray() As Integer() Return Array(1, 2, 3, ...) End Function End Module

call it for instance myVariable() and type stays Integer.

Thank you, but I am not sure if I got it right.
As I understand - each time, that I need to get a value from the array, it would call this function where the array is “defined”.

Well, let me try to describe…
Depending on the users interaction i have different arrays

Global Function MyArray() As Integer()
If SituationA then
RETURN Array(1,2,3) // array A
elseif SituationB then
RETURN Array(3,4,5) // array B
elseif SituationC then
RETURN Array(7,8,9) // array C
end if
End Function

I would like to switch the Array depending on the situation ONCE and store it in the global variable.
But this function would mean, that each time, I need to access a value from the array, the script would need to check the if-then-procedur, correct? That does not look efficient to me. How to improve?

Sorry for Noob question… :slight_smile:

You have to define the property as myNameForTheProperty() as integer
In you need to setup this property with different values based on a situation you can write

Sub setUpMyArray() If SituationA then myNameForTheProperty = Array(1,2,3) // array A elseif SituationB then myNameForTheProperty = Array(3,4,5) // array B elseif SituationC then myNameForTheProperty = Array(7,8,9) // array C end if End Sub

NO, NO, NO !

Global Function MyArray() As Integer

The variable is an array. The type does not change.

[quote=333030:@Michel Bujardet]NO, NO, NO !

Global Function MyArray() As Integer

The variable is an array. The type does not change.[/quote]
You are wrong. The parentheses after MyArray are the empty parameter list, the parentheses after Integer are to indicate the return type which is an array of Integers, so this was correct:

Global Function MyArray() As Integer()

[quote=333015:@Ursula Gaßner]How to make an Array global?
I added a new Property and in inspector I put “Integer()” for the type. That creates a Syntax Error.[/quote]

No need for global functions and all the rest of the misidrection
Put the () after the NAME of the property - not after Integer

name() as integer

OK. Fine. You are always right, of course, as usually, in your own logic :confused:

The OP asked about a property. WTH do you need to embark her into a function ?

[quote=333015:@Ursula Gaßner]How to make an Array global?
I added a new Property and in inspector I put “Integer()” for the type. That creates a Syntax Error.[/quote]

  • Add a module to your project
  • Add to it the property myArray() (or whatever name with two parenthesis at the end)
  • Make it an Integer (NOT an Integer())

A global property. As you cannot initialize an property typed as array in the IDE you have to do it in code. And IMHO it is valid to advise to do that in a getter of a (computed) property. And since computed properties are not supported for arrays, a method acting as a getter is the best solution. Better than initializing it in App.Open or somewhere else.

Why make it simple for a beginner when you can make it obscure and complex ?