Advanced expression validation

Dear Survey Solutions Developer Team,
I would like to know if there’s a way to us to use:
a) For, While, do, if-then-else;
b) Declare constant or variable (alpha and numeric);
c) Declare and using list, array (string or numeric);
in expression validation?

Thanks in advance for response,

A partial reply:

  • For the if-then-else construct, have a look under the “Other Useful Operators” section here. This is what C# calls the ternary operator.
  • For for/while loops, these are typically not needed. In places where loops might seem useful, there are better tools. For rosters and lookup tables, the C#'s query language, LINQ, allows one to search for things (e.g., any household head, number of female members, etc.). See this article for more details. For filter conditions, which dictate the answer options that should be shown, conditions “loop over” all answer options without the designer to write a loop. See this article for more details. If there are specific use cases where you need/want a loop, those would be easier to address on a case-by-case basis.
  • For creating constants or variables, see Survey Solutions’ variables here
1 Like

Survey Solutions provides full support of C# language features with some security related limitations. So all listed expressions are supported.

Thank you @arthurshaw2002 and @andrii. However, i don’t see how to port some existing CPL code to Survey solution. By example, i’m working on a way to know automatically if an enumerator is working on his affected area of interest (AOI). Usually, when we perform Census/Survey, we assign each enumerators to a specific area. So, i find a way to know if the enumerators is inside or outside of his AOI. If no, programmatically, enumerator isn’t allow to add new questionnaire, but only modifying an existing… I already have this code, and i can port it in C# but Survey Solution doesn’t give anyway (editor and compiler) to test it…

Survey Solutions has a function InRectangle() see the discussion here.

From what you describe it is sufficient to define a bounding box around every area of work and check that the GPS location is in that box, then open the whole questionnaire. The only way to open it is to arrive to the proper area and capture the GPS coordinates, and the subsequent edits may already take place from within or from outside the area.

You can add another GPS to the end of the questionnaire for an additional check.

Mind the accuracy of the GPS and accuracy of the underlying maps for the area boundaries!

Another function GpsDistanceKm() will give you distance (approx) between two points, so useful if you only have the centroid of the EA, without boundaries.

In any case with Survey Solutions having an idea is more important than having a code. Try to get to one of those week- or two-week long courses on Survey Solutions that the World Bank, the UN SIAP or the FAO where such details are discussed. Or inquire with your National Statistical Office or Bureau. Which country are you working in?

Best, Sergiy

Thank you Sergiy for your support. Theses functions are very important. However, we must have function regarding InPolygon() rather than a simple rectangle, since AOI may be whatever complexe polygon. Such algorithms already exist in C# and C++. It’s very important to allow application developer to use theirs own methods in theirs specific applications. I’m following your project very early: 2013. I remember discussing by mail years ago (2013-2014) with Mr Mlokshin and Mr Shaw They promised a strong programming language for flexibility. It’s not very fair to ask you all things, all the times… Please let me know how to port this:, in an application.
I’m working in Haiti.
Best Regards,

However point to polygon calculation algorithms exist in several packages. We also need this (distance between actual point and the boundary of an AOI). And for a specific application, allow us to implement and test them in C#. So, open expression validation as a normal C# compiler. Thanks in advance!

I’m very interested. However, i’m waiting for further development giving us way to implement our own idea in specific applications through a code editor and a compiler in your system: development of expression validation. I already coded a lot in CSPro, i would be very happy to take your long courses, since i want to port them to Survey Solution. With C# it’s possible to implement far more powerful and intelligent codes than CSPro.
Best Regards,