filewrite as report from a Roster

Discussions about CSEntry
Yass
Posts: 41
Joined: November 11th, 2017, 1:26 am

filewrite as report from a Roster

Postby Yass » May 17th, 2018, 4:29 am

Dear Cspro Team,
I am writing out a file as a report from a roster, the codes below compiles alright but no output.
The list of households are found in roster (HHROSTER) and i will like to generate a report per EA, based on the EA
selected all the households identified in the roster comes out. Hope i can be assisted here.

Code: Select all

function ReportGenerator1()

   string tempDirectory = pathname(Application) + "../temp/";
   dircreate(tempDirectory); // make sure directory exists
   setfile(ReportTxtFile, tempDirectory + "AllStructuresListed.txt");
   // Write report to file
   //string tempDirectory = pathname(Application) + "../temp/";
   dircreate(tempDirectory); // make sure directory exists
   setfile(reportFile, tempDirectory + "All Listed Cluster.txt");
   
   
   Open( LISTING_DICT );
    Xline=1;
   numeric i=1;
while loadcase( LISTING_DICT ) = 1   do 
do numeric ctr = 1 while ctr <= totocc(LISTING_DICT.HHROSTER)
  filewrite(ReportTxtFile, " ");
   filewrite(ReportTxtFile, "Report 1 - Supervisor Level");
   filewrite(ReportTxtFile, " -------------------------------------------------------------------------------");
   filewrite(ReportTxtFile, " │ ##  │Int.ID │EA Code│Struc.## │HH ID │ Detail Address│Househead Name│");
   filewrite(ReportTxtFile, " -------------------------------------------------------------------------------");

   filewrite(ReportTxtFile, "│02%d │ %3d   │ %10d   │     %4d │%2d  │  %40s │  %40s │",LID(ctr),Interv2(ctr),EACODE2(ctr),STRUCT2(ctr),LID(ctr),strip(ADDRESS2(ctr)),strip(LQ4(ctr)));

   ctr = ctr + 1;
enddo;   
enddo;   

   close(ReportTxtFile);

   // View report
   if getos() = 10 then
      // windows   
      execsystem(maketext("explorer.exe %s", filename(ReportTxtFile)));
   elseif getos() = 20 then
      // Android
      execsystem(maketext("view:%s", filename(ReportTxtFile)));
   else
      // Win universal
      errmsg("Reports not supported on this platform");
   endif;
      

end;


Thanks

Gregory Martin
Posts: 1009
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: filewrite as report from a Roster

Postby Gregory Martin » May 18th, 2018, 10:12 am

Have you checked whether or not the file is being created? Is it blank?

You might try changing totocc -> count and see if that works. Some of those occurrence functions behave strangely with external dictionaries.

Enkhbayar
Posts: 35
Joined: November 10th, 2014, 11:48 pm

Re: filewrite as report from a Roster

Postby Enkhbayar » May 21st, 2018, 9:57 am

you can call the function called "open()" after setfile().

setfile(reportFile, tempDirectory + "All Listed Cluster.txt");

OPEN(reportFile);

Open( LISTING_DICT );


Not related to your question, but I think it's better to move your report title to out of the loop. like below

filewrite(ReportTxtFile, " ");
filewrite(ReportTxtFile, "Report 1 - Supervisor Level");
filewrite(ReportTxtFile, " -------------------------------------------------------------------------------");
filewrite(ReportTxtFile, " │ ## │Int.ID │EA Code│Struc.## │HH ID │ Detail Address│Househead Name│");
filewrite(ReportTxtFile, " -------------------------------------------------------------------------------");

while loadcase( LISTING_DICT ) = 1 do
do numeric ctr = 1 while ctr <= totocc(LISTING_DICT.HHROSTER)

filewrite(ReportTxtFile, "│02%d │ %3d │ %10d │ %4d │%2d │ %40s │ %40s │",LID(ctr),Interv2(ctr),EACODE2(ctr),STRUCT2(ctr),LID(ctr),strip(ADDRESS2(ctr)),strip(LQ4(ctr)));

josh
Posts: 1601
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: filewrite as report from a Roster

Postby josh » May 21st, 2018, 11:03 am

You shouldn't need the open. Setfile automatically opens the file for you.


Return to “Entry”