Array Programe

define variable i as integer no-undo.
define variable a as integer extent 10 no-undo.

do i = 1 to 10:
a = random( 1, 100 ).
end.
 
i need to define the size of the array dinamically, for example
DEFINE VARIABLE nom AS CHARACTER EXTENT var NO-UNDO.<--- this is not posible
do you know another way
T.I.A

Vad
 
You are right, it is not possible, so you have a couple of options:

1. Make the extent bigger. (You can access the extent dynamically with EXTENT function).

2. If it has to be variable extent, then

a) use a temp-table or

b) if the array is simple, and unlikely to have too many entries, use a string with separators. In which case you might as well just make your extent bigger.
 
this could work:
DEFINE WORK-TABLE matrix NO-UNDO
FIELD element AS INTEGER
FIELD keyvalue AS CHARACTER.

DEFINE VARIABLE iCount AS INTEGER NO-UNDO.
DO iCount = 1 TO (pX * pY):
CREATE matrix.
ASSIGN matrix.element = iCount.
END.

where pX and pY are the dimensions that you want.
this example is an array definition.
 
Well, if you are talking about multiple extents, rather than variable extents, then you will have to use a temp table (or if you must, a work table).

If you know how many dimensions you will have, then your table could be defined like so (eg for 2 dimensions):

[pseudo code]

def temp-table matrix
field x
field y
field contents

if you are intending to reuse the construct, I would control access to it through a few methods, eg.

SetMatrix(x, y, contents)
GetMatrix(x, y)

but that's just me.

btw I'm not sure your method would work - how would you know key = 16 represented (4,4) and not (2,8), etc.
 
this could work:
element=((pX - 1) * iDimension[2]) + pY.<---this id for an array
But i need a vector not an array. more easy.
Vad
 
Back
Top