Arrays are great.
In a lot of languages they form the only temporary repository of related information you have access to and so are used and abused regularly.Perhaps because Progress has such quick and easy access to the database and temp-tables its array handling has been somewhat neglected. Oh and they start at 1, which to many programmers is a unforgivably bad form.
So what can you and cant you do?
You can define fixed length and indeterminate length arrays.
Fixed:DEF VAR MyArray AS INTEGER EXTENT 10.
Indeterminate:
DEF VAR MyArray AS INTEGER EXTENT.
Slightly weird syntax but there it is, once we have our indeterminate length array we can tell it how long it is.
EXTENT(MyArray) = 4.
But don't be fooled, our array is now permanently stuck at 4, so:
EXTENT(MyArray) = 4.
EXTENT(MyArray) = 5.
Will get you an error, it is in no way a dynamic or variable length array.
Initialising.
DEF VAR MyArray AS INTEGER EXTENT 5 INIT [1,2,3,4,5].
And you can clear out the whole array with a single line of code:
DEF VAR MyArray AS INT EXTENT 5 INIT [1,2,3,4,5].
DISPLAY myArray.
MyArray = 0.
DISPLAY myArray.
Comparisons.
Consider the following code snipit.DEF VAR MyArray AS INTEGER EXTENT 5 INIT [1,2,3,4,5].
DEF VAR YourArray AS INTEGER EXTENT 5 INIT [1,2,4,4,5].
MESSAGE MyArray = YourArray.
You might hope it would say "No" as the two arrays are different, no such luck...
---------------------------
Error
---------------------------
** Only individual array elements allowed in expressions. (361)
** Could not understand line 5. (196)
---------------------------
OK
---------------------------
To be fair Javascript would give a similar if rather less helpful, result.
<script>
var cars = [1,2,3,4,5];
var cars2 = [1,2,3,4,5];
alert (cars == cars2);
</script>
You get a "False" alert box, but its really asking if they are the same object, which of course they are not.
C, now that's were it's at, just two lumps of memory that are either the same or they aren't (ok, the same for the length of MyArray):
int MyArray[] = {1,2,3,4,5};
int YourArray[] = {1,2,4,4,5};
if(memcmp(MyArray,YourArray,sizeof(MyArray)) == 0)
I miss those days. Given how the Javascript result could lead you up the garden path its perhaps best that Progress at least gives a syntax error.
So you're left with the step by step:
DEF VAR YourArray AS INTEGER EXTENT 5 INIT [1,2,4,4,5].
DEF VAR vi AS INTEGER NO-UNDO.
DO vi = 1 TO EXTENT(MyArray):
IF MyArray[vi] <> YourArray[vi] THEN DO:
Message "Different".
LEAVE.
END.
END.
Sorting.
DEF TEMP-TABLE ttMyTable
FIELD iValue AS INTEGER.
DEF VAR MyArray AS INTEGER EXTENT 13 INIT [1,2,3,4,5,2,4,65,654,7,43,3,12].
DEF VAR vi AS INTEGER NO-UNDO.
DO vi = 1 TO EXTENT(MyArray):
CREATE ttMyTable.
ASSIGN
ttMyTable.iValue = MyArray[vi].
RELEASE ttMyTable.
END.
FOR EACH ttMyTable BY iValue:
DISPLAY ttMyTable.iValue.
END.
Sorted.