Page 1 of 1

multi occurrence

Posted: September 17th, 2011, 5:46 pm
by Guest
If I have multi occurrence items, how can I make sure a same value will not be entered twice?

I tried the codes below for a occ(2) item but it does't work.

*************************
if FIELD(1) = 1 and FIELD(2) = 1 then
errmsg("error");
endif;

if FIELD(1) in 1:3 and FIELD(2) in 1:3 then
errmsg("error");
endif;
*************************

How can I write the code?

Thank you

Re: multi occurrence

Posted: September 22nd, 2011, 1:01 pm
by Gregory Martin
Hello,

The easiest way to do is to use a loop, especially if you have more than two occurrences. See the attachment for an example. The relevant code is pasted here:
PROC VALUE

    
numeric i;
    
    
do i = 1 while i < curocc()
    
        
if VALUE(i) = VALUE then
            
errmsg("Must enter unique value");
            
reenter;
        
endif;
    
enddo;

Re: multi occurrence

Posted: September 23rd, 2011, 8:55 am
by lls
Thank you.

This will be very useful.

Re: multi occurrence

Posted: October 4th, 2011, 8:16 am
by Guest
This is a nice tip.
But it will count a "blank" value as a value.

If I have an occ 10 and input data as 1,2,5,7 the only way to go to the next fiels is by using the command ctrl-/
Entering more than 1 blank value will generate an error message.

Is there any way exclude blank from the loop?

Re: multi occurrence

Posted: October 4th, 2011, 8:46 am
by lls
This seems to work but not sure if it is the best way

numeric i;

do i = 1 while i < curocc()
if $(i) = notappl then
skip to next $

elseif $(i) = $ then
errmsg("Must enter unique value");
reenter;
endif;
enddo;

Re: multi occurrence

Posted: October 4th, 2011, 12:42 pm
by lls
While the code above do work for a multiple occurrence field in a single record, I could not make it work in a multiple occurrence field in a multiple occurrence (3) record. I tried various way but no luck.

How could I adapt this code in a multiple record?

Re: multi occurrence

Posted: October 4th, 2011, 12:46 pm
by Gregory Martin
If you want to skip blanks, it might be easiest (and clearest) to account for this before the loop:
PROC VALUE
    
numeric i;

if VALUE <> notappl then

    
do i = 1 while and i < curocc()

        
if VALUE(i) = VALUE then
            
errmsg("Must enter unique value");
            
reenter;
        
endif;

    
enddo;

endif;

Re: multi occurrence

Posted: July 5th, 2012, 4:53 pm
by Guest
Thank you.
It worked like this:

numeric i;

if VALUE <> notappl then

do i = 1 while i < curocc()

if VALUE(i) = VALUE then
errmsg("Must enter unique value");
reenter;
endif;
enddo;
else;
endif;

Re: multi occurrence

Posted: September 12th, 2012, 7:52 pm
by htuser
Sometimes i have the same problem with different questionnaires unique number. Often, data entry operators or interviewers, enumerators uses the same ID for different's case when they uses separate computer: The codes you proposed isn't adapted because the case unique ID's doesn't have subscript and cant compare ID for different cases (previous and active case).
Please can you help me with? By exemple we can assign automatically ID's range for computers, data entry operators (1:500 for a operator's name, 500:100 to another name etc).
Other, it's possible to assign username and password for data entry operators?

Sincerely

Re: multi occurrence

Posted: September 13th, 2012, 10:53 am
by Gregory Martin
You could add an alpha field to the IDs that would contain the computer's login name. Then you would populate that automatically by using the getusername function:

http://www.csprousers.org/help/html/get ... nction.htm