Pointer to Array

Previous topic - Next topic

StuC_Ovine



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






Moru

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


Kitty Hello

ALIAS labl AS atest[124]
labl.x = 123

StuC_Ovine


is that only at compile time tho ?


StuC_Ovine


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

Works like a charm .....  many thanks