how to add to variables
Hi,
This seems like a basic question, but I can't work out what I am doing wrong.
I have two variables, and I want to create a third variable that is to be the result of taking the second from the first.
So I have written this:
let result1 := (select 'PL Matches').'Mark/Ben Total';
let result2 := (select 'PL Matches').'Ben/Mark Total';
let result3 := result1 - result2
The third line isn't accepted by Ninox (though it will accept the third line if I replace the "-" with a "+" ,which I find baffling). I have tried using 'sum' to calculate result3 but this doesn't make any difference.
Can anyone point out my (presumably obvious) error?
Many thanks.
Mark
3 replies
-
Hi Mark
This is a common newbie gotcha! Your line
(select 'PL Matches').'Mark/Ben Total'
doesn't return a number. It returns an array, even if it only finds one record. If you are confident it will indeed only find one record you can turn this into a number by using the first() function. It take the value of the first element of the array. So your code needs to say
let result1 := first((select 'PL Matches').'Mark/Ben Total'); let result2 := first((select 'PL Matches').'Ben/Mark Total'); let result3 := result1 - result2
It is useful to read up all about arrays in Ninox. They are a foundational part of the code set and learning how to manipulate them will stand you in good stead.
Regards John
Content aside
- 7 mths agoLast active
- 3Replies
- 70Views
-
3
Following