Function 'CopyArray' does not work (v5.0)

gerba
Member Posts: 37
Hi all!
I am struggling with the function 'CopyArray'.
Documentation describes:
"Use this function to copy one or more elements in an array to a new array."
The Example is:
"If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5:
COPYARRAY (array2,array1,6,5);"
In my case array1 has dimension 8 and array2 has dimension 12.
All I want is to copy all elements of array1 to array 2.
I tried this:
COPYARRAY(array2,array1,1);
And got this message:
"Array dimensions should be identical."
Also this did not work:
COPYARRAY(array2,array1,1,8);
What do I overlook?!
Please help me!
Gerald
I am struggling with the function 'CopyArray'.
Documentation describes:
"Use this function to copy one or more elements in an array to a new array."
The Example is:
"If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5:
COPYARRAY (array2,array1,6,5);"
In my case array1 has dimension 8 and array2 has dimension 12.
All I want is to copy all elements of array1 to array 2.
I tried this:
COPYARRAY(array2,array1,1);
And got this message:
"Array dimensions should be identical."
Also this did not work:
COPYARRAY(array2,array1,1,8);
What do I overlook?!
Please help me!
Gerald
0
Comments
-
when using copyarray, you have to fill all the elements of the destination array so, in this code you have
b array = 12
a array = 8
i=integer
I am going to copy 8 elements from the 12 array to the 8 array with this instructionFOR i := 1 TO 12 DO BEGIN b[i] := i END; COPYARRAY(a,b,5);
orFOR i := 1 TO 12 DO BEGIN b[i] := i END; COPYARRAY(a,b,1,8);
and this returns errorFOR i := 1 TO 12 DO BEGIN b[i] := i END; COPYARRAY(a,b,1,7);
0 -
The message "Array dimensions should be identical" tells you all you need to know, apparently both arrays must have the same dimension property. Read the C/SIDE Reference guide for more detailed information about COPYARRAY.0
-
DenSter wrote:The message "Array dimensions should be identical" tells you all you need to know
I disagree. Based on the example provided in Help the array dimensions clearly do NOT have to be identical:Example
If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5.
COPYARRAY (array2,array1,6,5);
It's a very bad error message that doesn't tell you what the actual problem is.0 -
matttrax wrote:DenSter wrote:The message "Array dimensions should be identical" tells you all you need to know
I disagree. Based on the example provided in Help the array dimensions clearly do NOT have to be identical:Example
If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5.
COPYARRAY (array2,array1,6,5);
It's a very bad error message that doesn't tell you what the actual problem is.
I agree with you mattrax...the error is somewhat misleading...i've never used this function a lot, and at the beginning i also tought it was a bug...and as you can see in my previous post, it's not immediate to solve this problem (at least for me :whistle: )0 -
matttrax wrote:DenSter wrote:The message "Array dimensions should be identical" tells you all you need to knowExample
If array1 is an integer array with dimension 10, and it contains the numbers from 1 to 10, the following command copies the numbers 6,7,8,9,10 to array2, an integer array with dimension 5.
COPYARRAY (array2,array1,6,5);
It's a very bad error message that doesn't tell you what the actual problem is.
He's trying to put 8 elements into an array of 12, which fails because they do not have the same number of elements, the message is crystal clear to me. The example you are quoting there is copying an array of 5 (5 elements starting with element number 6) into an array of 5, which has the same number of elements. Granted the source array has 10 elements, but the command only tries to copy 5 elements into an array of 5 elements. It's a whole nother discussion as to why they wouldn't allow a small array to be copied into a larger array, but the message itself is very clear to me.
It's clear that the COPYARRAY command doesn't work, so program a little loop and you're done.0 -
It doesn't work in a situation where you want to copy an array of 8 elements into an array of 12, and he's going to have to find an alternative.
Here's the syntax for COPYARRAY:
COPYARRAY(NewArray, Array, Position [, Length])
The last parameters is Length. If you have a 10 element array, and you want to copy 5 of its elements into a 5 element array, you specify length as 5, just like the example that specified Position=6 and Length=5 to copy into a 5 element array. At that moment, your target as well as your source are both 5 elements, and COPYARRAY will work. It doesn't look at the actual source array, but at the 5 elements you're providing.
Apparently the command doesn't like it when your source array has fewer elements than the target array, it just needs identical numbers of elements. It wants you to provide as many elements as the target array.
It works exactly the way that I expect it to work, and the message is crystal clear to me. It means that if you want to copy x elements into an array that has more than x elements, you're going to have to loop through the elements in C/AL code and assign them that way.0 -
So what I said before:DenSter wrote:The message "Array dimensions should be identical" tells you all you need to know, apparently both arrays must have the same dimension property.0
-
DenSter wrote:It doesn't work in a situation where you want to copy an array of 8 elements into an array of 12, and he's going to have to find an alternative.
Here's the syntax for COPYARRAY:
COPYARRAY(NewArray, Array, Position [, Length])
The last parameters is Length. If you have a 10 element array, and you want to copy 5 of its elements into a 5 element array, you specify length as 5, just like the example that specified Position=6 and Length=5 to copy into a 5 element array. At that moment, your target as well as your source are both 5 elements, and COPYARRAY will work. It doesn't look at the actual source array, but at the 5 elements you're providing.
Apparently the command doesn't like it when your source array has fewer elements than the target array, it just needs identical numbers of elements. It wants you to provide as many elements as the target array.
It works exactly the way that I expect it to work, and the message is crystal clear to me. It means that if you want to copy x elements into an array that has more than x elements, you're going to have to loop through the elements in C/AL code and assign them that way.
about the error: you have two array of 5 elements, then you fill only the first 4 of the first array.
then you use the copyarray function to move the elements to the 2nd array and BANG!error...
the first thing I think is to take a look to array dimensions, which are the same...after that...what I have to do if i follow the error as is?0 -
DenSter wrote:So what I said before:DenSter wrote:The message "Array dimensions should be identical" tells you all you need to know, apparently both arrays must have the same dimension property.
exactly what I want to say
0 -
Sometimes you get sad reading threads. You haven't got a single helpful reply.
forget copyarray it not working as documented, use your own, its pretty simple:
FOR i := 1 TO ARRAYLEN(OriginalArray) DO
NewArray := OriginalArray;0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions