mibuso.com

Microsoft Business Solutions online community
It is currently Tue May 21, 2013 9:16 pm

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 3:29 pm 
Offline

Joined: Fri Dec 19, 2008 10:43 am
Posts: 28
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


Top
 Profile E-mail  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 4:36 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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 instruction
Code: Select all
FOR i := 1 TO 12 DO BEGIN
  b[i] := i
END;
COPYARRAY(a,b,5);


or

Code: Select all
FOR i := 1 TO 12 DO BEGIN
  b[i] := i
END;
COPYARRAY(a,b,1,8);


and this returns error
Code: Select all
FOR i := 1 TO 12 DO BEGIN
  b[i] := i
END;
COPYARRAY(a,b,1,7);


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 4:36 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
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.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 5:12 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Fri Feb 03, 2006 10:15 pm
Posts: 2272
Location: Houston, TX
Country: United States (us)
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:

Quote:
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.

_________________
Matt Traxinger - ArcherPoint
Microsoft Dynamics NAV 2009 Programming Cookbook
Do you have an idea to improve NAV? Submit it at I Love NAV


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 5:15 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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:

Quote:
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: )


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Tue Mar 24, 2009 9:09 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
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:
Quote:
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.

Well I have to disagree with your disagreement Matt :mrgreen:
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.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Wed Mar 25, 2009 9:31 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
but the COPYARRAY DOES work!
maybe not exactly in the way you expect, but it works!


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Wed Mar 25, 2009 3:36 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
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.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Wed Mar 25, 2009 3:51 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Thu Jan 02, 2003 6:37 pm
Posts: 7931
Location: Howell, MI
Country: United States (us)
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.

Is not entirely correct. It doesn't look at the Dimension property of the variable, but the number of elements that are provided by COPYARRAY. So, Matt, I stand corrected, the message indeed doesn't actually say what is wrong. BUT having worked with NAV for all this time I guess I'm used to interpreting these messages, and have never found this particular message to be unclear.

_________________
Daniel Rimmelzwaan
MVP - Dynamics NAV


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Wed Mar 25, 2009 3:52 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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.

yes, the strange thing of the function is the fact that you can't copy 3 elements in a array with max 5 elements...THIS is the thing that confused me.
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?


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Wed Mar 25, 2009 3:53 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Mon Dec 11, 2006 10:34 am
Posts: 2863
Location: Bergamo
Country: Italy (it)
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.

Is not entirely correct. It doesn't look at the Dimension property of the variable, but the number of elements that are provided by COPYARRAY. So, Matt, I stand corrected, the message indeed doesn't actually say what is wrong. BUT having worked with NAV for all this time I guess I'm used to interpreting these messages, and have never found this particular message to be unclear.

:mrgreen: exactly what I want to say


Top
 Profile  
 
 Post subject: Re: Function 'CopyArray' does not work (v5.0)
PostPosted: Thu Feb 09, 2012 9:21 am 
Offline

Joined: Tue Feb 26, 2008 9:36 pm
Posts: 47
Location: Stockholm
Country: Sweden (se)
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[i] := OriginalArray[i];


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: