CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
Post Reply
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by lmoriba »

Dear CSPRO Community,
I need some urgent help. Am working on a farm roster. However, depending on the number of crop fields the farmer has, I want to be able to copy the the value in some fields to their ensuing current occurrences. I discovered that the syntax I developed to copy works only once for numeric fields but can work for any number of times for alpha fields. However, I want it to work for the numeric field up to any number of times. The copy syntax are as follows:

IF MORE_HOLDERS = 2 THEN
CI0_HID(CUROCC()+1) = CI0_HID(curocc());
CI0_NAME(curocc() + 1) = CI0_NAME(curocc());
NFIELDS(CUROCC()+1) = NFIELDS(CUROCC()) -1 ;
skip to next FIELD_ID;
endif;

CI0_HID, NFIELDS are numeric fields, CI0_NAME is alpha. Attached is the application am trying to build:
Household_Quest.zip
(538.29 KiB) Downloaded 176 times
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by aaronw »

The problem is you're skipping to FIELD_ID which is ahead of C10_HID, C10_NAME, NFIELDS. Notice how the field is grey? This is telling you that the variable is now off path and won't be written to the data file when the case is closed. As a convenience to the enumerator the value still exists if you tab back in case the skip was in error.

Instead use skip to next to move to the next occurrence.
IF MORE_HOLDERS = 2 THEN
   
CI0_HID(curocc()+1) = CI0_HID(curocc());
    CI0_NAME(
curocc() + 1) = CI0_NAME(curocc());
    NFIELDS(
curocc()+1) = NFIELDS(curocc()) - 1 ;
   
skip to next;
endif;
Then in the C10_HID, C10_NAME, NFIELDS you'll need to advance the cursor if MORE_HOLDERS = 2. A protected field will be advanced through, so I toggle field protected on and off to get the behavior you want.
preproc

    if curocc
() > 1 and visualvalue(MORE_HOLDERS(curocc() - 1)) = 2 then
        setproperty
($, "Protected", "Yes");
   
else
        setproperty
($, "Protected", "No")
   
endif;
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by lmoriba »

Thanks 😊 Aaronw for the useful suggestions. However, when I tried to implement it I ran into the following error given below:

"Warning Out of range! Please enter a valid value for C10_HHID(2,1,1)"

Image


The problem I thought is related to the synthax below:
Please did you check if these coding is working?




preproc

    if curocc() > 1 and visualvalue(MORE(curocc() - 1)) = 2 then
        setproperty($, "Protected", "Yes");
    else
        setproperty($, "Protected", "No")
    endif;

So, the problem is still there...
Thanks......
Attachments
Untitled.png
Untitled.png (130.16 KiB) Viewed 2968 times
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by aaronw »

In the if statement update MORE to MORE_HOLDERS.
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by lmoriba »

Dear Aaron,

I did that and the program compiled successfully. However, during the test I got the error message as stated above. Please find attached program with your suggested coding for your attention.
Attachments
hhq.zip
(568.67 KiB) Downloaded 157 times
lmoriba
Posts: 56
Joined: June 10th, 2018, 6:21 pm

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by lmoriba »

Dear Aaronw,

I want to thank you sincerely. The codes you suggested indeed worked. The error message I posted yesterday was triggered by the dynamic value setting meant to bring holders from the previous section. The dynamic value setting was put in the onfocus of the variable CI0_HID whilst the toggled to protect on and off on the same variable was put in the preproc. However when I put both coding in the onfocus of the CI0_HID as shown below the applications started to work fine.

PROC CI0_HID

onfocus

if not(curocc() > 1 and visualvalue(MORE_HOLDERS(curocc() - 1)) = 2) then
// Create the value set for respondent from all household members 12 and over
valueset eligibleHoldersVSet;

do numeric indexRoster = 1 while indexRoster <= totocc(DEMOGRAPHICS_ROSTER)
if B11(indexRoster) in 1,3 and seek(CI0_HID = IDNO(indexRoster)) = 0 then
eligibleHoldersVSet.add(B1(indexRoster),indexRoster);
endif;

enddo;

setvalueset(CI0_HID, eligibleHoldersVSet);
endif;



if curocc() > 1 and visualvalue(MORE_HOLDERS(curocc() - 1)) = 2 then
setproperty($, "Protected", "Yes");
else
setproperty($, "Protected", "No")
endif;

So, I want to thank you once again.
aaronw
Posts: 561
Joined: June 9th, 2016, 9:38 am
Location: Washington, DC

Re: CAN'T COPY THE VALUE OF NUMERIC FIELD MORE THAN ONCE

Post by aaronw »

Great! Glad you were able to get it working.
Post Reply