Copy to array

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

Copy to array

Post by kevclark64 »

I mentioned some issues with Copy to Array a while back, which have been fixed, but I don't think I ever mentioned this. When you use Copy to Array with Foxpro, the length of the array will be truncated to the number of the items copied. With XSharp, the original length of the array remains unchanged regardless of items copied. So, in Foxpro if you dimension an array as 1000 items but then Copy to Array copies 50 items then the array now has a length of 50. In XSharp, doing the same thing would keep the array at 1000 items.
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Copy to array

Post by robert »

Kevin,
I have made a ticket for this, so we will not forget it:
https://github.com/X-Sharp/XSharpPublic/issues/1262

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
robert
Posts: 4520
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

Copy to array

Post by robert »

Kevin,
kevclark64 post=26422 userid=5303 wrote:I mentioned some issues with Copy to Array a while back, which have been fixed, but I don't think I ever mentioned this. When you use Copy to Array with Foxpro, the length of the array will be truncated to the number of the items copied. With XSharp, the original length of the array remains unchanged regardless of items copied. So, in Foxpro if you dimension an array as 1000 items but then Copy to Array copies 50 items then the array now has a length of 50. In XSharp, doing the same thing would keep the array at 1000 items.
I just tested this in FoxPro with the following code:

Code: Select all

SET DEFAULT TO "C:Test"
PUBLIC ARRAY aTest(10,5)
USE Categories
COPY TO ARRAY aTest
? RECCOUNT() && 8
? FCount()   && 4
? ALEN(aTest)    && 50
? ALEN(aTest,1) && 10
? ALEN(aTest,2) && 5
? aTest(1,1), aTest(1,2), aTest(1,3), aTest(1,4) && 1, Beverages, .F., .F.
? aTest(8,1), aTest(8,2), aTest(8,3), aTest(8,4) && 8, Seafood  .F., .F.
? aTest(9,1), aTest(9,2), aTest(9,3), aTest(9,4) && .F., .F., .F., .F.
USE
The example file is the Categories table from the Northwind database. This has 8 rows and 4 fields. The last 2 fields are memo.
After running the test, the array has the size it had before and the memo fields are not stored in the array.
So it looks like FoxPro does not resize the array.
Or am I overlooking something?


Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
kevclark64
Posts: 127
Joined: Thu Aug 15, 2019 7:30 pm
Location: USA

Copy to array

Post by kevclark64 »

I have to apologize because I made a mistake here. I'm not sure what I was doing when I got the results I reported, but the FoxPro help is clear that the array isn't truncated: Each successive row in the array is filled with the contents of the next record in the table. If the array has more rows than the table has records, any remaining rows aren't changed. If the array has fewer rows than the table has records, any remaining records aren't stored to the array.

Again, apologies for the error.
Post Reply