GLBasic forum

Main forum => GLBasic - en => Topic started by: Gary on 2011-Mar-14

Title: Correct use of GLOBAL?
Post by: Gary on 2011-Mar-14
I like to try to keep any production code free from any warnings just in case something goes wrong its one less thing to look at but am struggling with the use of the GLOBAL command.

I assume all the globals should be set right at the top of the program and is as simple as

Code (glbasic) Select
GLOBAL variable_name

for everything used that is a global variable

The example gives

Code (glbasic) Select
GLOBAL array_name[]

for defining arrays but if I try

Code (glbasic) Select
GLOBAL array_name[][]

I get syntax error.

How do you define a 2 and 3 dimensional array as a global?

Thanks
Gary
Title: Re: Correct use of GLOBAL?
Post by: backslider on 2011-Mar-14
Hi!

Your solution is:

Code (glbasic) Select

//define the array
Global array[]

//set the array dimensions
DIM array[4][3]
Title: Re: Correct use of GLOBAL?
Post by: Gary on 2011-Mar-14
ah thanks for that, I did try that and it seemed to work but wondered if because it was defined in the global as a single dimension and then set as a 2 dimension if it would cause problems
Title: Re: Correct use of GLOBAL?
Post by: ampos on 2011-Mar-14
Beware you can access multidimensional Variabkes as single-dimensions and GLB will not say anything.

A[12]=A[12][0]