Monday, November 17, 2014

Xojo: Creating a report from a listbox

Initial disclaimers: The code presented here is not my own. My goal is to fill in some of the blanks when it comes to learning to create a simple report from a listbox in Xojo. There isn't a lot about Xojo out there and I feel the more information that is presented in various formats, the more likely people are discover the beauty of Xojo (formerly known as RealBasic or Real Studio).

Step 1:
Put something in the listbox! The code I used comes from here. I imported a csv file so I didn't need the code to write to the listbox, just to read it. As a result, I just skipped the write portion of the code. I also added a button called "Load" to the window and put this code under the Load action event.

Step 2:
Watch this video and read the Examples folder under Printing and Reporting. That's where the rest of my code came from. The Examples folder is in Xojo and you'll see it on the sidebar when Xojo first opens.

Step 3:
Under App, choose the appropriate window. Otherwise, you won't see anything. It's a small step and one I overlooked. I drove myself nuts trying to figure out why nothing was displaying as planned.

Step 4:
As one of my Xojo friends explained, if you have a Mac, you will be able to preview the report as a PDF. Pretty cool since that's mostly what you'll want to do - preview the pdf, email the pdf. But in Windows, that functionality isn't present and, unfortunately, it's still a work in progress in Xojo itself, although, high up on the to-do list. There are a couple of options, besides just literally printing out the entire report.
      a) Use the Dyna plugin but it's not free. However, if you're creating an app to make money and not just for fun, it might be worth the cost. Like the Xojo license, it's not unreasonably priced.
      b) Create your own pdf framework. This is outside my realm of knowledge.
      c) Use OneNote. It came with my laptop on Windows 8 and I accidentally discovered that while I can't view the report as a pdf, I can view it in OneNote and that has the same effect. This isn't the prettiest report but it gives you an idea of what you can do. You'll see the Address and Subdivision fields from the report that are the column headings here. ***Note that the DataFields in the Inspector should use the same name as the original fields. The CSV report I used named the fields, "Address" and "Subd" and those are the names in the DataFields. In the text property in the Inspector, you can enter whatever text you want.
You can see how I put all the code together in GitHub. If anyone feels it would be useful, I will write down step-by-step what  I did. It didn't seem necessary as I wouldn't have really added anything to the sources cited above. So unless I hear otherwise, Happy Reporting!



No comments:

Post a Comment