problem for loadcase() from the beginning

Discussions about CSEntry
Post Reply
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

problem for loadcase() from the beginning

Post by Jing Liu »

Hi,

I wrote a function trying to get the list of clusters and households assigned to a interview from external dictionary "sampleplus" (with key variable to be household id). I would like to loadcase from top to buttom to find the case with device code match the tablet she/he is using. the device code is one of the variable in the external dictionary 'sampleplus' but not the key one.

The function I would like to use is ListClusHHasgn(), I also attached two more function related to this.

My problem is that, when i use the function for the first time, it works fine. but when I go back to the accept menu reselect the option, the function will not loadcase() from the first one but the third one. I guess It may related to the fact that I use locate() later? But how can I force the loadcase() to read the file from the first case whenever i use the function?



thanks!!

Jing




onfocus

{Interface for main menu}
heading = concat( "Interview device ID: ", ThisDeviceCode );
action = accept( heading,
" 1 Start household data collection ",
" 2 Revisit incomplete/partial household ",
" 3 Modify/review a complete household ",
"----------------------------------------",
" 5 Start individual data collection ",
" 6 Revisit incomplete/partial individual ",
" 7 Modify/review a complete individual ",
"-----------------------------------------",
" 9 Transfer data to supervisor ",
" 10 Send reference files to another device ",
" 11 Receive reference files from another device ",
" 12 Exit system (Esc)" );

if action = 0 or action = 12 then // exit system
stop(1);
elseif action = 9 then; //transfer data to supervisor
elseif action = 10 then; //send reference files to another device
elseif action = 11 then; //receive reference files from another device
elseif action in 1:3 then //household interview
xQuesType = 1;
elseif action in 5:7 then //individual interview
xQuesType = 2;
endif;

ListClusHHasgn(xQuesType);




function related below:


{function to remove dupliate case in array, may needed during generating dynamic valueset}
function ArryDupRemv(ArryNum, array ArryDup, array ArryClean )
k = 0;
m = 0;
do varying i=1 while i<=ArryNum
do varying j=1 while j<i
if ArryDup(j) = ArryDup(i) then
m=m+1;
endif;
enddo;
if m=0 then
k=k+1;
ArryClean(k) = ArryDup(i);
elseif m>0 then
m=0;
endif;
enddo;
ArryDupRemv = k; //export final number of array cases
end;

{Get list of cluster IDs and household IDs (for either HH interview or RSI interview) assigned to this device}
function ListClusHHasgn ( QuesType )
n = 0; {Number of households assigned to this device}
errmsg("n is %d", n);
while loadcase(SAMPLEPLUS) do
errmsg("shhid is %05d", shhid);
if QuesType = 1 then //Enter household questionnaire
if EDEVICE_CODE = SHHINTVDEVICE then
n=n+1;
arryClusTemp(n) = SCLUSTER;
arryHHTemp(n) = SHHID;
endif;
elseif QuesType = 2 then //Enter RSI questionnaire
if EDEVICE_CODE = SRSIINTVDEVICE then
n=n+1;
arryClusTemp(n) = SCLUSTER;
arryHHTemp(n) = SHHID;
endif;
endif;
enddo;
if n>0 then // remove duplicate cluster IDs
ArryClusLnum = ArryDupRemv( n, arryClusTemp, arryClusList ); //Number of clusters assigned to this device
ArryHHLnum = ArryDupRemv( n, arryHHTemp, arryHHList ); //Number of clusters assigned to this device
else
ArryClusLnum = 0;
ArryHHLnum = 0;
endif;
ListClusHHasgn = ArryHHLnum; //export number of households/RSIs assigned to this device
end;


{Get list of household IDs for either HH interview or RSI interview assigned to this device by cluster ID}
function ListHHAsgnClus ( xClusterID )
j = 0; {Number of households assigned to this device by cluster ID}
do i = 1 while i <= ArryHHLnum
if locate( SAMPLEPLUS, =, edit("99999", arryHHList(i)) ) = 1 then
retrieve (SAMPLEPLUS);
if SCLUSTER = xClusterID then
j=j+1;
arryHHListClus(j) = arryHHList(i);
endif;
endif;
enddo;
ArryHHLnumClus = j;
ListHHAsgnClus = ArryHHLnumClus; // export number of households assigned to this device by cluster;
end;


{Get list of household IDs for either HH interview or RSI interview assigned to this device by cluster ID}
function ListHHAsgnClus ( xClusterID )
j = 0; {Number of households assigned to this device by cluster ID}
do i = 1 while i <= ArryHHLnum
if locate( SAMPLEPLUS, =, edit("99999", arryHHList(i)) ) = 1 then
retrieve (SAMPLEPLUS);
if SCLUSTER = xClusterID then
j=j+1;
arryHHListClus(j) = arryHHList(i);
endif;
endif;
enddo;
ArryHHLnumClus = j;
ListHHAsgnClus = ArryHHLnumClus; // export number of households assigned to this device by cluster;
close(SAMPLEPLUS);
end;
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: problem for loadcase() from the beginning

Post by josh »

Your suspicion that the problem is related to locate is probably the issue. Before doing your top to bottom search of the file you can use locate with >= and "" to point to the first case in the file. Only start the loop after doing that:


locate(SAMPLEPLUS, >=, "");
while loadcase(SAMPLEPLUS) do
etc...
Jing Liu
Posts: 42
Joined: July 1st, 2015, 3:19 am

Re: problem for loadcase() from the beginning

Post by Jing Liu »

Hi,

Thanks Josh, it works fine now! My problem is solved!

I was thinking it was caused by some located() function i used after this function, but could not figure out how it happened. I add close(Sampleplus) into the function with located(), but did not solve it. So I guess close(sampleplus) does not change the position found by locate().

Thanks a lot!!

Now I am moving to another problem and see you soon!! :)

best

Jing
Yana
Posts: 51
Joined: October 6th, 2016, 6:57 am

Re: problem for loadcase() from the beginning

Post by Yana »

Hey guys can you attach the cspro application that you present the above programs.
Post Reply