multi occurrence

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
Guest

multi occurrence

Post 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
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: multi occurrence

Post 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;
Attachments
noRepeat.zip
(2.42 KiB) Downloaded 515 times
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multi occurrence

Post by lls »

Thank you.

This will be very useful.
Guest

Re: multi occurrence

Post 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?
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multi occurrence

Post 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;
lls
Posts: 109
Joined: December 6th, 2011, 3:11 pm
Location: Geneva, Switzerland

Re: multi occurrence

Post 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?
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: multi occurrence

Post 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;
Guest

Re: multi occurrence

Post 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;
htuser
Posts: 631
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: multi occurrence

Post 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
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1777
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: multi occurrence

Post 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
Post Reply