How can I add two arrays?
Any idea how you can add arrays in NINOX
let a := 1;
let b := 2;
let c := 3;
let d := 4;
let ar1 := [a, b, c];
let ar2 := [d];
let ar3 := [ar1 + ar2];
ar3
This will give the result 1234 instead of 1,2,3,4
Thanks
23 replies
-
Hi Ιωάννη,
get some ideas here:
Νίκος
-
With concat() ?
-
I'm not sure why the Ninox team made array manipulation so difficult. It's like they wanted arrays to be read-only after the arrays are defined. One way is to break the arrays down and then rebuild them like this...
let a := 1;
let b := 2;
let c := 3;
let d := 4;
let ar1 := [a, b, c];
let ar2 := [d];
let ar3 := concat(ar1) + ", " + concat(ar2);
let ar4 := split(replace(ar3, ", ", ","), ",")
You can combine the lines for ar3 and ar4, but I separated them so it would be easier to see what's going on.
-
Nice timing Steven :)
One of the problems with this approach is now your array values are text instead of number and if you want to do any arithmetic with the values you will have to convert them to number type like...
number(item(ar4, 1))
-
thank you Sean
i guess it would be very complicated to have as a result an array of numbers then ?
-
Hi,
In order tp get an array as a result you can use the function
unique()
:myMultipleChoiceField := unique(numbers(ar2), 2, 7)
Best, Jörg
-
@Ioannis, it's possible and once you have the code worked out it will do all the work for you. Post what you want to do and I will try to help.
@Jörg, that just returns the values that are not of type array, ie, 2 & 7.
-
Hi Sean,
if the
ar2
in my example is an array of numbers (I just took it form your example), the formula should give back an array with all unique numbers.Best, Jörg
-
Hi Jörg,
numbers() is not a function in the Mac app. Here is a screenshot of my test...
-
Hi Sean,
numbers() works only to get an array out of a Multiple choice field.
The formla according your example should be:
let a1 := [3,5];
let a2 := unique(arr1,2)Sorry, for the confusion.
Best, Jörg
-
Hi Jörg,
Thank you for posting this. The array request has been going on for some time now... is this recently implemented functionality?
Best, Sean
-
Hi Sean Thank you for the help
No it is not a new feature but one that is not well documented in the manual
So another question
How can a make an array from the string
Zhu Ling, Fu Ling, Che Qian Zi, Ze Xie, Yin Chen, Chi Shao, Mu Dan Pi, Huang Bai, Zhi Zi, Niu Xi
-
I thing i got that
let x := split("Zhu Ling, Fu Ling, Che Qian Zi, Ze Xie, Yin Chen, Chi Shao, Mu Dan Pi, Huang Bai, Zhi Zi, Niu Xi", ",")
item (x,1) -
Ioannis You’re welcome. Looks like you’ve got it.
I’m familiar with the unique() function’s named purpose, but was not aware that it would combine an array with other values. The topic of arrays has gone on for several months now and this is the first time I’ve seen this solution.
-
Hi Sean
I managed to solve the problem of adding two string arrays
I am stuck though in trying to add two numeric arrays
let a := 1;
let b := 2;
let c := 3;
let d := 4;
let ar1 := [a, b, c];
let ar2 := [d];
let ar3 := [concat(ar1) + ", " + concat(ar2)];
'Multiple choice' := ar3I tried a lot of different combinations and always get the error
-
Hi Ioannis
That is one of the problems with those array functions at the moment... they always return text values regardless of the input type. Another problem is any value/item that has a "," in it (ie, "Acme, Inc") will cause the value to be split at that point because you can't choose the concatenating character in the concat() function; strange considering you have to choose the splitting character in the split() function.
Jörg's solution using unique() works well as long as you don't need to duplicate items in your array. It solves the number value issue as well as the "," issue.
-
Ioannis
Sorry, I got two threads mixed up in my head. In your example ar3 becomes an array with a single item equal to "1, 2, 3, 4". You can test this with item(ar3, 0). If you use any other index you will get null as the return value because there is now only one item in the array
-
No problem Sean
I dug a little and found a solution
let array := numbers('Multiple choice');
let max := cnt(array) + 1;
let add := 10;
var newArray := for ind from 0 to max do
if ind = max - 1 then add else item(array, ind) end
end;
'Multiple choice' := newArrayWith this formula you can read the existing array from a multiple choice field, add one more and write it back to the same field
i post this for someone that maybe will need
-
Yes, I'm familiar with that thread. I'm curious why you would choose that approach instead of one like this...
let array := numbers('Multiple choice');
let add := 10;
array := unique(array, add)
Do you have duplicate values?
-
I just noticed that it could have reduced it to 2 lines...
let array := numbers('Multiple choice');
array := unique(array, 10)
You can also use it with slice() to insert items...
let myArray := [1,2,3,4,7,8,9];
myArray := unique(slice(myArray, 0, 4), 5, 6, slice(myArray, 4, 7))
The second index position of the slice() function is not inclusive.
-
Hi Sean
Thanks a million
The first one works perfectly!!!
And it is very simple!!!
-
works, but I can't find a documentary about it
let mA := ["A", "B", "C"];
let mB := ["X", "Y", "Z"];
let mC := array(mA, mB);
concat(mC)
-
Johannes, you can find the information here...
https://ninox.com/en/manual/calculations/reference-of-functions-and-language
Content aside
- 3 yrs agoLast active
- 23Replies
- 6890Views