ALEN()

This forum is meant for questions about the Visual FoxPro Language support in X#.

Post Reply
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

ALEN()

Post by kevclark64 »

I noticed that if you have an array of dimension 5,2 then ALEN(array) in Foxpro would return 10 but ALEN(array) in X# returns 5. Foxpro has an extra parameter to ALEN to return rows or columns, which X# does not support currently. However passing just the array gives the total elements across all dimensions in Foxpro. The FoxPro function list mentions ALEN as a function which works but not exactly with the same parameters. But it seems like if the same parameter is passed then it would be good to get back the same result.
User avatar
Chris
Posts: 4978
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

ALEN()

Post by Chris »

Thanks Kevin for the report, I think we'll need to declare separate VO and VFP versions of the function to make it work for both dialects.
Chris Pyrgas

XSharp Development Team
chris(at)xsharp.eu
User avatar
robert
Posts: 4558
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

ALEN()

Post by robert »

Kevin,

The potential problem that I see with FoxPro arrays is that they are not really multi dimensional, but they emulate multi dimensions. Consider the following code

Code: Select all

DIMENSION myarray(5,2)
? ALEN(myarray)
myarray[1] = 10    && this sets element [1,1] 
myarray[1,2] = 12 
? myarray[1,1]    && 10
? myarray[2]     && 12, so this reads element [1,2]
FOR i = 1 TO 10
	? i, myarray[i]
	myarray[i] = i
NEXT
* you can even access undefined columns and rows
* in other xbase dialec ts all of the following would crash
? myarray[2,4]  && 6 ?
? myarray[3,3]  && 7 ? 
? myarray[9]     && 9 ?
In most of the other dialects this mixing of single and multi dimensional approach will not be possible.
When you declare an array as [5,2] then the first element of the array is a sub array of 2 elements.
Assigning 10 to it would remove the sub array in the first element and accessing it with a 1,1 index later would cause an exception because the sub array has been replaced with a single numeric value.
And in other XBase dialects accessing element myarray[2] would return an array of 2 elements and not a single value.
I am sure that internally FoxPro uses single dimensional arrays always and it somehow calculates the position in this array by calculating a single dimensional offset in the array from the dimensions used.
And FoxPro even allows to use positions outside of what has been defined !

I personally think this was a design flaw in FoxPro. An array that is declared as multi dimensional should not allow to be treated as single dimensional and accessing 'undefined' positions show throw an exception.


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
mainhatten
Posts: 200
Joined: Wed Oct 09, 2019 6:51 pm

ALEN()

Post by mainhatten »

robert wrote:I am sure that internally FoxPro uses single dimensional arrays always and it somehow calculates the position in this array by calculating a single dimensional offset in the array from the dimensions used.
True and it will bite you if you ReDim without first saving contents to re-populate redimensioned array.
I personally think this was a design flaw in FoxPro. An array that is declared as multi dimensional should not allow to be treated as single dimensional and accessing 'undefined' positions show throw an exception.
Array functionality was added early in the DOS years - and Fox made certain old programs will run in new versions. That kept some code p[w]arts alive...As in xSharp typed arrays should be the target to aim for, relegating such crazy behaviour to USUAL datatype hopefully will eliminate it from user code in time.

my 0.002€
thomas
Post Reply