birdie
3rd January 2012, 17:18
A happy new year to who ever this reads!

I need some help on usage of common variables.
I create a session with following code:

declaration:
string globe.ploc (3) BASED
string globe.plocs (1,1) BASED
common globe.ploc
common globe.plocs

before.program:
globe.ploc = "ZZZ"
alloc.mem(globe.plocs,3,10)
inlezen.plocs()

end()

functions:
function inlezen.plocs()
{
select bibbm042.*
where bibbm042._index1 = {:logname$}
as set with 1 rows
selectdo
globe.plocs(1,1) = bibbm042.ploc0
globe.plocs(1,2) = bibbm042.ploc1
endselect

}

Then in a second session I want to use the same variables again, so I add following code again:
declaration:
extern string gg(3)

string globe.ploc (3) based
string globe.plocs (1,1) based
common globe.ploc
common globe.plocs

before.program:
alloc.mem(globe.plocs)
gg=globe.plocs(1,1)


But now my problem: the globe.ploc works ok, but from the array I loose my values I did in prior piece of code. I assume due to the alloc.mem function. But if I don't use I get an error, EMPTY variables. What do i have to do in order to be able to use the values of globe.plocs from first piece of code?

JaapJD
3rd January 2012, 20:42
I think you can use the at.base() function.

zardoz
9th January 2012, 11:40
Only a question. Why you use the dynamic allocation of memory? There is no use if all the time the array size don't vary; just declare:

string globe.plocs(3, 10)

The dynamic allocation of memory can be useful when the dimension(s) can vary at each run of the session, but if they are always the same...