GLBasic forum

Main forum => GLBasic - en => Topic started by: mentalthink on 2009-Oct-22

Title: Array Question
Post by: mentalthink on 2009-Oct-22
Hi, I´ve got a doubt about arrays.
How I can put vaiables in a bidimensional array, in one dimension I make something like this
Code (glbasic) Select

dim myArray[5]
myArray[5].xpos=300

for 2 dimensional array, I stay frozen here
Code (glbasic) Select

dim myArray[5][3]=300
myArray[5]???=???  ???

I don´t kwon the sintaxis for more of one dimension Array, for put in a value for every dimension.

Thanks for your time and help.

Best regards mentalthink




Title: Re: Array Question
Post by: Kitty Hello on 2009-Oct-22
Code (glbasic) Select

DIM data[100][100]

data[x][y] = z // no space between ] and [ !!
Title: Re: Array Question
Post by: mentalthink on 2009-Oct-22
HI, kitty thanks!!!

But the trouble is what I want put a variable for x and another for y

DIM data[100][100]

data
Title: Re: Array Question
Post by: Moru on 2009-Oct-22
array
Title: Re: Array Question
Post by: Hemlos on 2009-Oct-22
mentalthink,
Make sure you dont overstack your arrays.

if you declare DIM array[10]

then the bounds range is [0..1..2....8..9]

so this would overstack:

array[10]=12345

and this would be your last slot, and no overstack:

array[9]=12345

an overstack causes crash.
Title: Re: Array Question
Post by: Schranz0r on 2009-Oct-22
You can put X and Y like this:


Code (glbasic) Select

TYPE MyArray
    x
    y
ENDTYPE

GLOBAL MyCoolArray[] AS MyArray

REDIM MyCoolArray[10][10]

MyCoolArray[1][3].x = 123
MyCoolArray[1][3].y = 321


and so on...
Title: Re: Array Question
Post by: mentalthink on 2009-Oct-22
HI, Moru, Hemlos and Schranz0r, thanks for your explanations, it´s are very good for me, to continue growing my littles knowledges about programming..

Thanks again for your time, and answers.

Best Regards, Iván J.