CSPro logic in CAPI text issue

Discussions about CSEntry
Post Reply
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

CSPro logic in CAPI text issue

Post by htuser »

Dear CSPro Developer Team,
I was trying to display an already filled roster in the CAPI text part. It's because I would like to visualize rosters on Android devices during data entry. However, I failed. In the CAPI text part, CSPro automatically deactivate any CSPro logic codes written inside <? ?> tag. In the attached demo the result is

Code: Select all

<!--? do numeric ctr = 1 while ctr <= count(CSPROLOGICCAPTEXT_DICT.RECORD2)?-->
and

Code: Select all

<!--? enddo; ?-->
Please take a look inside the attached demo app and let me know if you have a workaround for this issue.

I would also like to know if there's a way to customize the CAPI text part size for a specific item.
Thanks in advance,
Attachments
CAPI Text Demo.zip
(4.02 KiB) Downloaded 172 times
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: CSPro logic in CAPI text issue

Post by Gregory Martin »

Unfortunately this will not work. The question text evaluation only supports ~~ and ~~~, whereas reports also include the <? ?> functionality. These systems were designed separately, but perhaps we will integrate them at some point.

In the meantime, your best option is to create the HTML table in CSPro logic and then insert it into your question text with ~~~, which will preserve the HTML characters (instead of escaping them as ~~ would do).

Code: Select all

~~~CreateHtmlTable()~~~
function string CreateHtmlTable()

    string html = "<table>";

    // ... use encode("your text") when adding text like "<>" that needs escaping

   
exit html + "</html>";

end;
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: CSPro logic in CAPI text issue

Post by htuser »

Thanks Greg for your support. However, I spent some times trying to transform explanations you provided in results. But, I failed. I never used and until now I'm not sure I have a good understanding of the encode function.
create HTML table in CSPro logic
I always created HTML table in CSPro logic using file.write and the new way bellow. For the actual purpose, I don't want to create a HTML file, but displaying a dynamic table with results in the CAPI text part. When CSPro Android support rosters, this will not be necessary... ;)

Here's the table that I would like to display in the CAPI text part.
    <table class="table table-striped table-bordered">
        <thead>
            <tr>
                <th>
Household Number</th>
                <th>
Structure Number</th>
              <th>
Household within structure</th>
                <th>
Latitude in degrees</th>
                <th>
Longitude in degrees</th>
            </tr>
       
<? do numeric i = 1 while i <= totocc(RECORD2) ?>
           
<tr>
                <td>
~~visualvalue(LNUMBER(i))~~</td>
                <td>
~~visualvalue(LSTRUCT(i))~~</td>
               <td>
~~visualvalue(LNUMBER(i))~~</td>
               <td>
~~visualvalue(LHOUSEH(i))~~</td>
               <td>
~~visualvalue(LLATITUDE(i))~~</td>
            </tr>
       
<? enddo; ?>
       
</thead>
    </table>
   
Please, can you or any other members of the CSPro Developer Team help me in displaying it in the CAPI Text part ?
Thanks in advance,
G.VOLNY, a CSProuser from Haiti, since 2004
Gregory Martin
Posts: 1796
Joined: December 5th, 2011, 11:27 pm
Location: Washington, DC

Re: CSPro logic in CAPI text issue

Post by Gregory Martin »

You use encode when you're writing out data that may need to be escaped for HTML, such as text that includes "< or >" characters. However, if you're just writing out numbers, you don't need to worry about it. You would do something like this:
function string CreateHtmlTable()

    string html;

    do numeric i = 1 while i <= totocc(RECORD2)
        html = html + maketext("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>,
                              
visualvalue(LNUMBER(i)), visualvalue(LSTRUCT(i)), visualvalue(LNUMBER(i)),
                               visualvalue(LHOUSEH(i)), visualvalue(LLATITUDE(i)));
    enddo;
   
    exit html;

end;
And then in your CAPI text:
  </thead>
 
~~~CreateHtmlTable()~~~
</table>
htuser
Posts: 632
Joined: December 19th, 2011, 6:26 pm
Location: Silver Spring Area, MD, USA

Re: CSPro logic in CAPI text issue

Post by htuser »

Thanks a lot Greg for this very clear explanation and the logic you posted. This will simplify lot of things I wrote before to deal with HTML tables in CSPro logic.

However, I made basic corrections to have it working well.
function string CreateHtmlTable()

    string html;

    do numeric i = 1 while i <= totocc(RECORD2)
        html = html + maketext("<tr><td>%v</td><td>%v</td><td>%v</td><td>%v</td><td>%v</td></tr>",
                               visualvalue(LNUMBER(i)), visualvalue(LSTRUCT(i)), visualvalue(LNUMBER(i)),
                               visualvalue(LHOUSEH(i)), visualvalue(LLATITUDE(i)));
    enddo;
  
    exit '<table class="table table-striped table-bordered"><thead>'+html+"</thead></table>";

end;
and in the CAPI Text I only put:

Code: Select all

  ~~~CreateHtmlTable()~~~
Best,
G.VOLNY, a CSProuser from Haiti, since 2004
Post Reply