Either the "For Each" uses or the "Assign" activity writes to a variable it isn't supposed to

As seen in the picture - the Assign activity called “Assign B” writes a value to both array variables - arr_MileageValues and arr_MileageValues2, as seen in the “Locals” window, with red outline.

the For Each activity that contains the “Assign B” activity has been explicitly instructed to only write to arr_MileageValues2.

As can also be seen in the “Locals” panel, the current iteration number, or index is 1, meaning 1 iteration has been done up to this point, which is also reflected in both array variables.

The correct value for the first item of the array variable arr_MileageValues is connected and shown via blue lines. After the first iteration of the loop the value of the first item in arr_MileageValues should be - " Up to 100 miles (24,496)" instead of “Up to 100 miles”. The same correct value can be seen just above arr_MileageValues in the “Locals” panel, in the string str_MileageValues, which the array was derived from.


It’s because array is reference type. Please see the following document in details.

If you need to copy contents of the array, can you try to use Copy method as the following?

arr_MileageValues2 = arr_MileageValues.Copy


1 Like

Thank you mvp Yoichi!

Your suggestion worked perfectly.

I hope you can understand, how someone new to this stuff can easily see this as a bug. :wink:

I thought the assign activity would just create a new variable, and then wondered why the assign inside the for each loop even touched the first array.

Mods, or whoever is responsible - feel free to lock this topic, move it to help section or whatever else you deem necessary.

Regards, Oscar


This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.