Creating a Report

From BKeeney Shorts Documentation
Jump to: navigation, search

Class Setup

Creating a report with BKeeney Shorts is relatively easy, but since all the work is done via code it can be somewhat confusing for the first time. Shorts reports are created with object oriented principles, so start by making a class to use as a report object. For simplicity here, the report object class will be called rptDemo.

The report class needs a place to store pages and a method to create them.
To store pages create a private property for the class to store an array of BKS_Shorts.Page items.
To create pages, a method that returns an array of BKS_Shorts.Page items.

Private maroPages() as BKS_Shorts.Page
Protected Function CreateItemReport() as BKS_Shorts.Page()

Putting Items on the Page

The first step in putting items on a page is to create the page! Determine the desired size of the page in Points.
For the purpose of Shorts, there are 72 points per inch (2.834 points per millimeter). This equates to 612 points by 792 points for the US Letter 8.5" x 11" paper size. It may be useful to store these values as constants.

dim oPage as new BKS_Shorts.Page(612, 792)

Now, with a page to put items on, place items by creating objects using the BKS_Shorts classes and appending them to the page object. For example, to add text to the page:

dim oTitle as new BKS_Shorts.TextItem("Item Listing", 24, 18, 200, 20)

This will create a new TextItem with the text "Item Listing" 24 points away from the left margin, 18 points from the top margin. The other parameters will size the TextItem 200 points wide, 20 points tall. The final (and very important step) is to append the page.

Next, put a line on the page below the header text for decoration.

dim oHeaderLine as new BKS_Shorts.LineItem(18, 28, oPage.Width - 18, 28)

Continue to add items to the Page object in this manner until the page is completed. When the page is done, add it to the array of pages in the report object class.
Remember to track the positioning of items on the page, and break onto new pages by creating them as necessary!


Generating a Report

To generate the report and use it for display and printing, create a new instance of BKS_Shorts.Document and append the pages in order to the document object.

// Create a new instance of a BKS_Shorts Document object
dim oDoc as new BKS_Shorts.Document

// Run the report, and get a document to use
for each oPage as BKS_Shorts.Page in rptDemo.CreateItemReport()

In this example, the rptDemo class already has a connection to the data source, generates pages, and returns them from the CreateItemReport function.

At this point the Document object can now be used. See Using the Report