ComponentOne VSView Reporting Edition
Desktop Scenarios

In typical desktop scenarios, VSReport8 runs on the same computer where the reports will be generated and viewed (the report data itself may still come from a remote server).

These scenarios assume that VSReport8 will be hosted in a Visual Basic or Visual C++ application (other platforms, such as Borland C++ Builder, are supported as well, although not specifically mentioned in this documentation).

Scenario 1: Embedded Reports

Under this scenario, an application generates reports using a fixed set of report definitions that are built into the application. This type of application does not rely on any external report definition files, and end-users have no way to modify the reports.

The main advantage of this type of application is that you don't need to distribute the report definition file, and you can be sure that no one will modify the report format. The disadvantage is that to make any modifications to the report, you must recompile the application.

To create an application with embedded reports, follow these steps:

  1. Use the VSReport8 Designer to create all the reports you will need. (See the Designer documentation below for details on how to do this.)

  2. Add one VSReport8 control for each report definition you want to distribute. You may want to name each control after the report it will render (this will make your code easier to maintain).

  3. Use the Load Report property page to load the report definitions into each respective control. To access the Load Report property page, right click the control and select Properties from the context menu. The property page looks like this:


    To load a report, click the "..." button to select the report definition file you created in step 1, then select the report from the drop-down list and click the Load button. The property page will show the name of the report you selected and a count of groups, sections, and fields.

  4. Add a single VSPrinter control to the form and add a control that will allow the user to pick a report (this could be a menu, a list box, or a group of buttons.)

  5. Add code to render the report selected by the user. For example, if you added a group of buttons in step 4, the code would look like this:

    Example Title
    Copy Code
    Private Sub btnProductsReport_Click()
    
      vsrProducts.Render vp
    
    End Sub
    

    Where vsrProducts is the name of the VSReport8 control that contains the report selected by the user and vp is the single VSPrinter control on the form.

Scenario 2: Reports Loaded at Run Time

Under this scenario, an application loads reports definitions from a file at run time. This type of application requires a report definition file and works like a viewer.

The main advantage of this type of application is that if you modify the report format, there's no need to update the application. Simply send the new report definition file to the users and you are done.

To create an application with reports loaded at run time, follow these steps:

  1. Use the VSReport8 Designer to create all the reports you will need. (See the Designer documentation for details on how to do this.)

  2. Add a VSReport8 and a VSPrinter control to the application.

  3. Add code to read the report definition file and build a list of all reports in it. This can be done as follows:

    Example Title
    Copy Code
    ' get a tab-separated list all reports
    
    ' in the definition file
    
    sFile = App.Path & "\MyReports.xml"
    
    sList = vsr.GetReportInfo(sFile, vsrRIList)
    
    vList = Split(sList, vbTab)
    
     
    
    ' populate list box
    
    cmbReport.Clear
    
    For i = 0 To UBound(vList)
    
      cmbReport.AddItem vList(i)
    
    Next
    

    The code uses the GetReportInfo method to retrieve a tab-separated list of all reports contained in the MyReports.xml report definition file (created in step 1), then parses the list and populates a listbox.

  4. Add code to render the report selected by the user. For example:

    Example Title
    Copy Code
    Private Sub Command1_Click()
    
      ' no reentrancy
    
      If vsr.IsBusy Then Exit Sub
    
     
    
      ' render report
    
      On Error Resume Next
    
      vsr.Render vp
    
      If Err.Number <> 0 Then
    
        MsgBox "Error " & Err.Number & _
    
                vbCrLf & Err.Description
    
      End If
    
    End Sub
    

    Note that the IsBusy property is used to prevent the user from starting the report a second time while it is still being rendered.

Scenario 3: Customizable Reports

This scenario is a variation on the above. It consists of loading the basic report definitions from a file, then writing code to customize the reports according to user selections.

For example, the code below changes the font used in the detail section:

Example Title
Copy Code
Dim i%, strDetailFont$

strDetailFont = "Arial Narrow"

With vsr.Sections(vsrDetail).Fields

  For i = 0 To .Count - 1

    .Item(i).FontName = strDetailFont

  Next

End With

The code below toggles the display of a group by turning its Sort property on or off and setting the Visible property of the group's header and footer sections:

Example Title
Copy Code
Dim bShowGroup As Boolean

bShowGroup = True

With vsr.Groups(0)

  If bShowGroup Then

    .SectionHeader.Visible = True

    .SectionFooter.Visible = True

    .Sort = vsrAscending

  Else

    .SectionHeader.Visible = False

    .SectionFooter.Visible = False

    .Sort = vsrNoSort

  End If

End With

These samples illustrate some of the things you can do to customize reports. There are infinite possibilities, because the object model offers access to every aspect of the report. (In fact, you can create whole reports entirely through code).

 

 


Copyright (c) GrapeCity, inc. All rights reserved.

Product Support Forum  |  Documentation Feedback