Technical Issues - Report Generator Tutorial II  - Advanced

The Report Generator becomes truly useful when reports include calculated results as well as graphs. For example 'Coating PASSED Specifications' based on average and maximum reflectance. While setting up reports requires some effort, QA technicians and other end-users need have no idea of the inner workings.


Creating Text: Action command FileText is useful for boilerplate text that's used repeatedly. A one line Report Template is all that is needed. In this case the template contains no font information so the default font is utilized.

<<FileText c:\Winfilm\Data\LoremIpsum.txt>>

The next step is to customize the text. One possibility is to generate the entire Report Template in BASIC. BASIC's Replace function can then substitute computed text.

Sub Main
    Open "c:\Winfilm\Data\LoremIpsum.txt" For Input As #1
    Do
        Line Input #1, s$   ' Read text file
        t$ = t$ & s$ & vbCrLf
    Loop Until EOF(1)
    Template$ = Replace$(t$, "fringilla", "*** HELLO KOBI-SAN ***")
    Close
    ReportPrint  ' Print report without displaying Report Generator
End Sub

Alternatively we can paste text into the Report Template and then use BasText to insert computed values. Since the Report Template is saved with the FILM Archive (Scan Method) this method is more portable as another user would not need a copy of LoremIpsum.txt. On the other hand, when there are several pages of boilerplate (as in 'Terms and Conditions') it makes sense to add these with FileText.

The Report Generator automatically replaces <<BasText n>> with quantity BasText(n) previously defined in BASIC as shown in the brief code sample below. Up to 16 quantities (n = 0...15) are possible.

Sub Main  ' Program c:\Winfilm\Basic32\Henry.bas
    BasText(0) = "*** HELLO HENRY ORR ***"
End Sub

A relatively new addition (July 2011) to the Report Template is BasExec whereby BASIC code is inserted directly in the Report Template. By first defining BasText(0) we ensure that its value is available when the Report Generator encounters <<BasText 0>>. BasExec automatically adds Sub Main and End Sub; the pipe symbol "|" separates lines of code.

While BasExec is suitable for short code segments, BasRun should be used for longer programs. In that case we could replace the BasExec action command with

<<BasRun c:\Winfilm\Basic32\Henry.bas>>

Another comparison of BasExec and BasRun can be found in Including Date/Time in a FilmStar Report. Another BasRun example is given here.


Using the Workbook: Consider how we might create a QA report for a BBAR 450-750 nm coating which passes if average %R is < 0.5% and maximum is < 1.0%. The computation can be performed in FilmStar BASIC, but it's easier to use the Workbook.

Normally <<WbText ..>> requires that the Workbook be open before the Report Generator is activated. This can be confusing in production. An enhancement implemented in DESIGN 2.65.3120 and MEASURE  2.51.1360 allows the Report Generator to open the Hidden Workbook. This is illustrated in the template code below followed by the PDF image (50%) of the final result.

<<Name Arial>><<Size 18>><<Align 1>><<Bold 1>>
FTG Software Associates
<<Name Lucida Sans Typewriter>><<Size 10>><<Bold 0>>
<<Review>><<BasExec WbOpenHidden "c:\Winfilm\Workbook\QCBBAR.xls">>

<<FSPlot 90,100,10500,8100>><<BasExec WbExecute "CALCULATE"|PlotNext>>
<<Name Arial>><<Size 18>><<Align 1>><<Bold 1>>
This coating <<WbText $E$10>> specifications.
<<BasExec WbCloseAll>>



Embedding BASIC Code:
Consider the report illustrated at the right. We need a monochrome graph with white background, not a green background web or PowerPoint graphic as shown here.

One way (not the only way) to ensure that an appropriate graph appears in the Report Generator is to execute BASIC code within the Report Template. This is accomplished with Action Command BasRun specifying a previous FSPlot configuration.

  <<Name Arial>><<Size 18>><<Align 1>><<Bold 1>>
  FTG Software Associates
  <<Name Lucida Sans Typewriter>><<Size 10>><<Bold 0>>
  <<Review>>
  <<BasRun c:\Winfilm\Basic32\FtgReport.bas>>
  
  <<FSPlot 90>>
  
  <<BasRun c:\Winfilm\Basic32\FtgWebGreen.bas>>

The optional final BasRun command restores original colors.

Downloads: FtgWebGreen.bas, FtgReport.bas, FtgReport.pdf. The PDF file was created directly with the Report Generator and does not require separate PDF creation software.
 



Poor FSPlot c
olors
for a printed report


Generating BASIC Code: As mentioned previously, Report Templates are stored in Graph Axes/FILM Archive or Scan Method files. This is convenient, but in some circumstances it might be preferable to generate Report Templates in BASIC code. Click File.. Create BASIC Code in the Report Generator window.

Sub Main
   ' Report Template code for FilmStar BASIC:
    Header = "FilmStar Report Generator||Page %d"
    Footer = ""
    Template = "<<Name Arial>><<Size 18>><<Align 1>><<Bold 1>>" & vbCrLf & _
    "FTG Software Associates" & vbCrLf & _
    "<<Name Lucida Sans Typewriter>><<Size 10>><<Bold 0>>" & vbCrLf & _
    "<<Review>>" & vbCrLf & _
    "" & vbCrLf & _
    "<<FSPlot 100, 100, 10500, 8100>>"
End Sub

Our final example shows how to assemble a printed coating design catalog. Since we want the same Report Template for various designs we need to override any template already attached to the FILM Archive.

Dim nPage As Integer

Sub Main
    nPage = 1        ' Starting page number
    PrintPage "boudot"
    PrintPage "laser"
    PrintPage "bbar" ' Add other PrintPage statements as required
End Sub

Sub PrintPage(film$)
    FileOpen film$, 8 ' Open FILM Archive
    AxesDraw: CalcPlot
    t$ = "<<Spacing 100>><<Margins 0,1.1,1,.75,.75>>" & vbCrLf
    t$ = t$ & "<<Name Lucida Sans Typewriter>><<Size 9>><<Bold 0>><<Italic 0>>"
    t$ = t$ & "<<HdrName Arial>><<HdrSize 14>><<HdrBold 1>><<HdrItalic 1>>"
    t$ = t$ & "<<HdrText |Edgerstoune Optics Coating Catalog - Design " & CStr(nPage) & "|>>"
    t$ = t$ & vbCrLf & vbCrLf & "<<FSPlot 100,110,7500,6500>>" & vbCrLf
    t$ = t$ & "<<Align 0>>" & vbCrLf
    t$ = t$ & "<<Review>>"
    Template = t$: ReportShow: PlotClose
    nPage = nPage + 1 ' Advance to next page
End Sub

What about FSPlot format? A Report Template containing BASIC code (as in Embedding BASIC Code) cannot be inside another BASIC program. Simply add FSPlot formatting code (as copied to the Clipboard in FSPlot's File.. Create BASIC Code) to Sub Main. Alternatively, run PlotConfig.bas before creating reports.

Hint...Suppose there are multiple spectra for which you require a a web graphic as well as a printout. Since you cannot readily change graph format while the FSPlot Module is open, use the FSPlot Data menu to save or copy all spectra. You can then close and reopen FSPlot and open or paste the spectra.
 


Updating Saved Templates:  Report Templates are saved in MEASURE/Scantraq Scan Method files (*.scw) and DESIGN FILM Archive (*.faw) or Graph Axes (*.axw) files. A user requested the ability to automatically attach the same template to all scan methods in a given directory. In this way QA technicians need not deal with BASIC macros. The same technique could be utilized in DESIGN for quotes, catalog sheets, etc.

BACK UP FILES BEFORE PROCEEDING!

Sub Main
    Dim s$
    s$ = Dir("c:\Winfilm\Measure\*.scw")  ' MEASURE
   's$ = Dir("c:\Winfilm\Designs\*.faw")  ' DESIGN FILM Archive
    AssignTemplate s$
    Do
        s$ = Dir
        If s$ = "" Then End ' Done!
        AssignTemplate s$
    Loop
End Sub

Sub AssignTemplate(ByVal f$)
    FileOpen f$  ' Open Scan Method or FILM Archive
    Header = "FilmStar Report Generator||Page %d"
    Footer = ""
   ' Recommended...include plot setup code
    Template = "<<BasRun c:\Winfilm\Basic32\PlotSetup.bas>>" & _
    "<<Align 1>><<Name Arial>><<Bold 1>><<Size 18>>" & vbCrLf & _
    "FilmStar Report Generator" & vbCrLf & _
    "<<DefFonts>><<Align 0>>" & vbCrLf & _
    "<<FSPlot 100,80,8500,7000>>" & vbCrLf & _
    "This is a FilmStar report."
    FileSave ,2  ' MEASURE re-saves Scan Method
   'FileSave Left$(f$, Len(f$)-4)& "_Rpt.scw",2 ' New file name (2.51.1412)
   'FileSave f$ ' DESIGN re-saves FILM Archive
End Sub

MEASURE 2.51.1412 adds BASIC Property DeviceMode which returns device type and scan mode (e.g. "PE 9 %R"). Use this to branch to different AssignTemplate routines according to instrument type. Alternatively, it is possible to branch according to file name, assuming names contain similar information. Press <F1> in the Report Template dialog and note the variety of format settings, including margins.

FSPlot graphs utilized in a report must have the same colors, fonts, etc. Since settings are easily modified, consider generating plot setup code to be executed by template action command BasRun before FSPlot, as illustrated in the above code sample. It is also possible to insert the code in the template and execute with BasExec. In that case the short Template = line is replaced by a single long line as follows.

Template = "<<BasExec PlotConfig 25526474, 2420, 0|PlotSize 8500, 7000, 92|PlotTitleFont = "Verdana"|PlotTitleSize = 110|PlotLegendSize = 100|PlotLegendSimple = False|PlotAxesFont = "Verdana"|PlotAxesLabelSize = 100|PlotAxesNumberSize = 100|PlotFontFixed = False|PlotFontFixedSize = 1|PlotAxesConfig = 0|PlotEdgeSpace 50, -25, 20, 30|PlotAxesSpace .15, .3, .3, 1.5|PlotBitmapMode = False>>" & _

Recall that Sub Main and End Sub are automatically added by BasExec and that "|" indicates next line. We did not include PlotColors, PlotTableColors, PlotTableGrid because the graph is monochromatic and there is no Plot Table. While the line is lengthy, eliminating the need for a separate BASIC file simplifies matters.

Once a general overall format has been implemented, a user might need to add legends and annotations for particular coating types, e.g. filter bandwidth or average %R. This is possible through additional BasRun or BasExec steps. While this might seem rather complicated, QA technicians ultimately require less training and make fewer mistakes.

Note: Recent versions of MEASURE (2.51.1400) run in Test Mode if a DESIGN key USB is attached. This is useful for developing templates, macros, etc.