Hello,
I have a pre-filled list of Personal ID Numbers (Variable Name: CNP) that I intend to load into a List Question. Later, I will open a Roster having that list question as source. Inside the Roster I want to use the Personal ID Number to determine the sex, using a variable of double type and the following expression:
Convert.ToDouble(CNP.Substring(0,1))
I’m receiving the following error at compile:
‘TextListAnswerRow[]’ does not contain a definition for ‘Substring’ and no accessible extension method ‘Substring’ accepting a first argument of type ‘TextListAnswerRow[]’ could be found (are you missing a using directive or an assembly reference?)
The formula above works when I collect the data from a Text question, but not from a List question.
How should I fix it?
.Where(p=>p.Item1==@rowcode) will filter out all list items BUT the one of your roster row. .First().Item2 will retrieve the Text associated with the respective value / roster row. .Left(1) will give you the first character from the left. You could also use Substring(0,1).
It is probably worth discussing why the original expression didn’t work. Because the list involves multiple values, you can’t operate on it as a single string. Peter correctly points to a definition of what is the exact data type for a list-type question.
We can probably rewrite the expression to pull out the information you want by utilizing the fact that we know that that list triggers the roster. This is the case where the user of the @rowindex is justified to result in a more readable:
CNP[@rowindex].Text.Left(1)
Note also that if you want to go the original way with lambda expressions, Where(condition).First() is equivalent to First(condition).
Conversion to double is questionable. A single digit will never be a fraction. Converting to an integer would be more reasonable. But if the objective is to display the information as a reference, then perhaps:
This solves the issue, but perhaps this could be solved alternatively. I guess from your description, that you are preloading the known members of the family or other unit. Hence you can preload not just the list of the IDs, but also any of their attributes, even those which are not directly obtainable from the ID, by simply placing a variable into the roster and preloading that variable together with the list.