How to assume -9 and -8 as null

Hello All,

I need your input concerning a question.

I have these fours A to D in numeric form, each question takes in the figure between 0 to 100.

The total of A to D must not be more 100 and each box is allowed to take in -9 as Don’t know and -8 as not relevant. My concern is, if -8 or -9 is entered, it will affect the total (100%). How can design my validation to assume -8 and -9 as null (ie. zero)? so that it doesn’t affect the sum at all.

Chinedu (TSLGS) Onyezobi,

you can except those values with the conditional operator

Best, Sergiy

You can create a variable of long integer type with Expression:
new [] { a, b, c, d}.Sum(x => (x ?? 0) > 0 ? x : 0)
Where a, b, c and d are variables for numeric questions with negative special values. new [] { a, b, c, d} will create an array with answers. Function Sum will calculate a sum of those value after applying some modifications to them:

  1. (x ?? 0) if question is not answered, use 0 as default
  2. (x ?? 0) > 0 ? x : 0). C# ?: Operator can be used to convert negative values to zeros. You can read the expression like this: if answer is greater than zero, use the answer, othrwise use zero

I shared with you sample questionnaire “Syntax 1”.