Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Description: This tutorial illustrates how create a PixelPerfect Report with Visual Basic Scripts. This Report calculates previous page totals using macros. You can use C#, Visual Basic or JavaScript to develop PixelPerfect Scripts. For a C# version of this tutorial refer to "How to Create Previous Page Totals with PixelPerfect C# Scripts".
Const allocationStep = 100 Dim currentPageTotal As System.Decimal = 0 Dim runningPagesTotal As System.Decimal = 0 Dim PageNumber As System.Decimal = 0 Dim PageTotal(allocationStep) As System.Decimal
Private Sub OnSummaryReset_currentPageTotal(ByVal sender As Object, ByVal e As System.EventArgs) PageNumber += 1 if PageTotal.Length <= PageNumber then ReDim Preserve PageTotal(PageNumber + allocationStep) end if PageTotal(PageNumber) = currentPageTotal currentPageTotal = 0 End Sub
This sub-routine is executed at the beginning of each new page.
Code:
Private Sub OnSummaryRowChanged_currentPageTotal(ByVal sender As Object, ByVal e As System.EventArgs) currentPageTotal += DetailReport.GetCurrentColumnValue("Total Sales") End Sub
This code is executed for each row in the page. It retrieves the value of the Total Sales field and adds it to the previous total. Remember to change the field name if you want to re-use the code for another field.
Add this code below the previous code.
Private Sub OnSummaryGetResult_currentPageTotal(ByVal sender As Object, ByVal e As SummaryGetResultEventArgs) e.Result = currentPageTotal e.Handled = True End Sub
This code returns the sum for the current page. It is executed when changing pages. Add this code below the previous code.
Private Sub OnSummaryGetResult_previousPageTotal(ByVal sender As Object, ByVal e As SummaryGetResultEventArgs) e.Result = PageTotal(PageNumber) e.Handled = True End Sub
This code return the total for the previous page. You don't need to insert a -1 in the array index. Add this code below the previous code.
Private Sub OnSummaryGetResult_runningPagesTotal(ByVal sender As Object, ByVal e As SummaryGetResultEventArgs) runningPagesTotal += currentPageTotal e.Result = runningPagesTotal e.Handled = True End Sub
This code increase the value of runningPagesTotal by the currentPageTotal and returns the value of the Total Sales of each preceding page. Add this code below the previous code.
Now we associate sub-routines to the events specified on the left column.
Do these steps also for the last Label. Insert OnSummaryGetResult_runningPagesTotal on Summary Get Result field.
Select Preview in the Actions group in the Reports window