Page 1 of 1

Add extra option in array

Posted: September 1st, 2016, 9:38 am
by khurshid.arshad
Dear Team

I am using this code from example and i want add extra code in the end for "Do't Know" after populate the list.
aDistrictCodes(i-1) = 999;
aDistrictNames(i-1) = "Don't Know";


Thanks.
arshad

Code: Select all

Preproc

{ use lookup file to load all sectors for district entered }
	LF_DISTRICT_ID = Q_1_2;
	if loadcase(SECTOR_DICT, LF_DISTRICT_ID) = 0 then
		errmsg("Invalid District, please reenter");
		Move to  Q_1_2;
	endif;

	{ Copy the district codes and names for the selected province into arrays.
	  Note that the AREA_REC record repeats (max occurences of 99) so when we
	  load the case for a given province, we get one occurence of AREA_REC
	  for each district in the given province.  }
	do varying i = 1 until i >= count(SECTOR_DICT.SECTOR_REC)
		{ the arrays that we use for setvalueset start at 0 so we use i-1! }
		aDistrictCodes(i-1) = LF_SEC_ID(i);
		aDistrictNames(i-1) = LF_SEC_NAME(i);
		
	enddo;
	
	aDistrictCodes(i-1) = notappl; { mark end of array with a code = notappl}
									{so that setvalueset knows how many elements}
									{ in the array to use }

	{ call setvalueset using the arrays that contain district codes and names }
	setvalueset(Q_2_3_4, aDistrictCodes, aDistrictNames);


Re: Add extra option in array

Posted: September 2nd, 2016, 9:34 am
by khurshid.arshad
Dear Josh and Gregory

I hope both of you are doing fine. I am using this code from an example and i want to add an extra code in the end for "Don't Know" after populating the list from the lookup file. This is very urgent. Please respond at the earliest opportunity.
Regards;
a.

Code: Select all

Preproc

{ use lookup file to load all sectors for district entered }
   LF_DISTRICT_ID = Q_1_2;
   if loadcase(SECTOR_DICT, LF_DISTRICT_ID) = 0 then
      errmsg("Invalid District, please reenter");
      Move to  Q_1_2;
   endif;

   { Copy the district codes and names for the selected province into arrays.
     Note that the AREA_REC record repeats (max occurences of 99) so when we
     load the case for a given province, we get one occurence of AREA_REC
     for each district in the given province.  }
   do varying i = 1 until i >= count(SECTOR_DICT.SECTOR_REC)
      { the arrays that we use for setvalueset start at 0 so we use i-1! }
      aDistrictCodes(i-1) = LF_SEC_ID(i);
      aDistrictNames(i-1) = LF_SEC_NAME(i);
      
   enddo;
   
   aDistrictCodes(i-1) = notappl; { mark end of array with a code = notappl}
                           {so that setvalueset knows how many elements}
                           { in the array to use }

   { call setvalueset using the arrays that contain district codes and names }
   setvalueset(Q_2_3_4, aDistrictCodes, aDistrictNames);

Re: Add extra option in array

Posted: September 3rd, 2016, 5:53 am
by Saint
Hi Arsad,
Try this:

Code: Select all

do varying i = 1 until i >= count(SECTOR_DICT.SECTOR_REC)
      { the arrays that we use for setvalueset start at 0 so we use i-1! }
      aDistrictCodes(i-1) = LF_SEC_ID(i);
      aDistrictNames(i-1) = LF_SEC_NAME(i);
enddo;
aDistrictCodes(i-1) = 999;
aDistrictNames(i-1) = "Don't Know";
aDistrictCodes(i) = notappl;
Hope the variable in question has a length of 3.

Best...

Re: Add extra option in array

Posted: September 4th, 2016, 2:39 am
by khurshid.arshad
Dear Saint;

Thank yoooou very much.
Regards.
Arshad