Line number of persons in a roster

Hello SS Team,
I want to make a new variable that returns an integer that corresponds to the line number of the Head of the household. So I have this code -

headLine = roster_dd.Where(x=>x.pRelate==1).Select(x=>x.@rowcode).ToArray()[0]
-and-
spouseLine = roster_dd.Where(x=>x.pRelate==2).Select(x=>x.@rowcode).ToArray()[0]

Then I use the functions in a validation rule -

pAge(headPointer) - pAge(spousePointer) > 40

The error I get back is “Non-invocable member … cannot be used like a method.”
Any workarounds?

Regards,
Pierre

correction -
Math.Abs((long)pAge(headLine) - (long)pAge(spouseLine)) > 40

Sorry another correction - I accidently used a parenthesis instead of the brackets for indexing -
Math.Abs((long)pAge[headLine] - (long)pAge[spouseLine]) > 40
But now I have a cast problem.

Pierre,

111111111111111111111111111111111111111111
the definition of pAge is missing from the above description. Assuming it is a roster triggered by the same question as the roster_dd the last syntax will be wrong since pAge[index] will still be an object (person record) and you still need to specify the question you want to refer to:
pAge[index].age

Assuming that pAge is a calculated variable, then the last syntax is wrong since no variable may be declared as an array by the user.

222222222222222222222222222222222222
Not sure about the check conceptually. What do you want to verify? assuming you don’t want too big of a difference between the man and his wife, the validation rule should be Abs(ageM-ageF)<40 , not >40.

333333333333333333333333333333333333
In general, @rowcode is not equal to the line number. But since (it seems to me) you are using it to subsequently refer to some attributes of the person with the same index, it should be ok. But if you ever want to do anything absolute (check the head is listed first) than this may not work.

Best, Sergiy

Thanks Sergiy,
I will try to modify my code based on suggestion 1.
For suggestion 2 - I like using the conditional statements it is easier for me to read so Abs(ageM-ageF) < 40 ? false : true . I just forgot to put the details of the validation. :slight_smile:

Thanks again for your help and enjoy your weekend.

Cheers,
Pierre

Hello Sergiy - It works like a charm!
Thanks for clarifying the problem with referencing the roster.