Array Question

Previous topic - Next topic

mentalthink

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





Kitty Hello

Code (glbasic) Select

DIM data[100][100]

data[x][y] = z // no space between ] and [ !!

mentalthink

HI, kitty thanks!!!

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

DIM data[100][100]

data
  • [y] = z // no space between ] and [ !!

    in your example, if I don´t stay wrong the value is put to x and y, but my doubt is what I want to put 2 values, one for x and another for y.

    Perhaps this can´t be done, I´m not programmer and my programming kwnledges are very little.
    Thanks Kitty, again.

Moru

array
  • [y] makes a two-dimensional array, see it as a spreadsheet with lots of boxes, each box can be addressed with an X and a Y coordinate or column and row if you want.

    (column, row)
    (0,0) (1,0) (2,0)
    (0,1) (1,1) (2,1)
    ...

Hemlos

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.
Bing ChatGpt is pretty smart :O

Schranz0r

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...
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

mentalthink

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.