Using the onkey Function to view arrays

Discussions about CSEntry
Post Reply
sergiofurtado
Posts: 25
Joined: October 5th, 2019, 1:43 pm

Using the onkey Function to view arrays

Post by sergiofurtado » November 4th, 2019, 7:09 pm

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!

josh
Posts: 1986
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Using the onkey Function to view arrays

Post by josh » November 5th, 2019, 5:56 am

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.

sergiofurtado
Posts: 25
Joined: October 5th, 2019, 1:43 pm

Re: Using the onkey Function to view arrays

Post by sergiofurtado » November 5th, 2019, 6:49 am

Thanks again Josh!

Gregory Martin
Posts: 1241
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: Using the onkey Function to view arrays

Post by Gregory Martin » November 5th, 2019, 7:03 am

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

Post Reply