GLBasic forum

Main forum => GLBasic - en => Topic started by: StuC_Ovine on 2009-Aug-24

Title: Pointer to Array
Post by: StuC_Ovine on 2009-Aug-24


Can I do this in Glbasic ?.  Im wanting to use a variable so that I can update the array a bit more elegantly.

Heres what I want todo

Code (glbasic) Select



TYPE testArrayType
a
ENDTYPE

GLOBAL atest[] AS testArrayType

LOCAL lab1 AS testArrayType

lab1.a = 1
DIMPUSH atest[], lab1   

lab1.a = 2
DIMPUSH atest[], lab1

// so now we have 2 items in the array,   atest[0].a = 1  and atest[1].a = 2

// I want to address atest[0] as lab1,  do a change and save the change back to atest[0]....
lab1 = atest[0] 
lab1.a = 99
DEBUG atest[0].a +"     " + atest[1].a
ALIAS

END





Title: Re: Pointer to Array
Post by: Moru on 2009-Aug-24
There are a few ways to do it if I understand you right in what you want. If you are running a big loop that you want to work on all items in atest[] you use FOREACH ... IN ... ; NEXT

Code (glbasic) Select

FOREACH temp IN atest[]
    temp.a = 90
NEXT


If you just want to operate on one item you could do it like this I believe:

Code (glbasic) Select

do_it(atest[0])

FUNCTION do_it: temp as testArrayType
    temp.a = 90
ENDFUNCTION

Title: Re: Pointer to Array
Post by: Kitty Hello on 2009-Aug-25
ALIAS labl AS atest[124]
labl.x = 123
Title: Re: Pointer to Array
Post by: StuC_Ovine on 2009-Aug-25

is that only at compile time tho ?

Title: Re: Pointer to Array
Post by: StuC_Ovine on 2009-Aug-25

I'll answer myself now Ive had chance to look at it ....

Works like a charm .....  many thanks