Page 1 of 1

Using the onkey Function to view arrays

Posted: November 4th, 2019, 7:09 pm
by sergiofurtado
Hello everyone,

I would like to consult them if it is possible through the onkey function to show the user the contents of an array. As an example, the questionnaire has 10 sections and the array to be shown was defined after the end of section 5.

Thus, if the user uses the onkey function it should not be activated until section 5, ie it should only be activated in sections 6 to 10.

Thank you!

Re: Using the onkey Function to view arrays

Posted: November 5th, 2019, 5:56 am
by josh
You could create a global variable that you initialize to zero. When you arrive at the end of section 5 you set the variable 1. In your OnKey function you only show the array if the variable is set 1.
numeric finishedSection5 = 0;

function OnKey(numeric x)
  
if  x = 2069 and finishedSection5 = 1 then
    
showarray(...);
  
else
    OnKey = x;
{ returnrest of keys }
  
endif;
end;

 
An alternative to using OnKey is to add a button to the userbar (https://www.csprousers.org/help/CSPro/u ... ction.html). This tends to be less hidden than using a key and will also work well on Android.

Re: Using the onkey Function to view arrays

Posted: November 5th, 2019, 6:49 am
by sergiofurtado
Thanks again Josh!

Re: Using the onkey Function to view arrays

Posted: November 5th, 2019, 7:03 am
by Gregory Martin
Another function that is little known in CSPro but is useful is the highlighted function. You can pass it a field name to check if that field has been entered, so you could write something like:
if highlighted(LAST_FIELD_IN_SECTION_FIVE) then
    // show array