Technical Issues - BASIC Tutorial II - Advanced BASIC

This page covers more advanced topics.
Other topics: Getting Started, Examples


When compared with VBA, FilmStar/Scantraq BASIC dialogs are more difficult to implement. It is possible, however, to modify dialogs and implement interactive dialogs containing dynamically updated fields.

Two modifications of Fnum32.bas are instructive. Fnum32Bold.bas implements bold dialog fonts. While fonts cannot be changed in the dialog editor, they can be changed when the dialog is initialized. This requires the somewhat obscure DialogFunc function (see DialogFunc Prototype in online help)

Begin Dialog UserDialog 372, 94, "Enter values", .DlgFunc
    Text 27, 23, 73, 13, "&F Number", .lblFnum
    ...
End Dialog

The inclusion of an optional field (i.e. .DlgFunc) in the Begin Dialog statement triggers a dialog function with the same name. Six actions (Case 1-6) are possible, but we only need to bold the fonts during initialization, so only Case 1 is required. 

Private Function DlgFunc(DlgItem$, Action%, SuppValue&) As Boolean
    Select Case Action%
    Case 1 ' Dialog box initialization
        SetBold "lblFnum", SuppValue
        SetBold "lblRes", SuppValue
        ...
    Case 2 ' Value changing or button pressed
    ...

Care must be taken with font substitutions since forms design is based on MS Sans Serif 8.

The second modification, Fnum32Ang.bas, shows how to update field values within a dialog. Changing the cone angle changes the f-number and vice-versa. Here we make use of Action = 3 (text box change).

    Case 3 ' Text box change
        Select Case DlgItem
        Case "txtFnum"
            DlgText "txtCone", CStr(ConeGet(Val(DlgText$("txtFnum"))))
        Case "txtCone"
            DlgText "txtFnum", CStr(FnumGet(Val(DlgText$("txtCone"))))
        End Select
    ...

Another option is to borrow an Excel form. This is not terribly difficult and is an excellent alternative if Excel is available, as it usually is. We have made use of this in setting up QA procedures for the aerospace industry.

FTG Software has frequently emphasized the benefits of Microsoft Excel. In the screen below (Calculate in Excel.bas) we see how Excel VBA methods are referenced, just as if Excel had been built into FilmStar.


Excel objects in FilmStar BASIC

The converse situation is illustrated in Run-DESIGN.xls. In some cases the Design1.exe reference is missing or incorrect. Problems are usually solved by simply deleting and re-adding the reference. Should that fail please visit FilmStar Class References.


Adding Design1.exe reference to Excel

DESIGN objects are exposed to Excel, just as if FilmStar had been built into Excel. Whether FilmStar or Excel should 'run the show' depends on particular circumstances.


FilmStar DESIGN objects in Excel

FilmStar BASIC is much enhanced through integration with other FilmStar Development Modules: FSPlot, Report Generator, and Workbook. Consider the following simple example:

Sub Main
    Template = "<<Name Arial>><<Size 64>><<Align 1>>Hello world!"
    ReportShow
End Sub

In automation it seems useful to have (as appropriate) a single command center, that is one file setting up the entire procedure. We might want the Report Template to be within BASIC code. In the following we make use of the BasExec function to store the time and date in BasText(0). For more about this technique click here. Copy the following BASIC program and try it.

Sub Main
    Header = "|FilmStar Report Generator|": Footer = ""
    Template = "<<Name Arial>><<Size 18>><<Align 1>><<Bold 1>>" & vbCrLf & _
    "FTG Software Associates" & vbCrLf & _
    "<<Name Courier New>><<Size 10>><<Bold 0>>" & vbCrLf & "<<Review>>" & _
    vbCrLf & "" & vbCrLf & "" & vbCrLf & "<<FSPlot>>" & vbCrLf & "" & vbCrLf & _
    "<<Size 18>><<BasExec BasText(0) = Cstr(Now)>>It is now <<
BasText(0)>>"
    ReportShow
End Sub

Since setting up a Report Template via BASIC would be tedious, the Report Generator can automatically generate BASIC code from the template. Click File.. Create BASIC Code. This is not the only BASIC code generator in FilmStar. There are two more in FSPlot: Annotations and Graph Details.

FilmStar BASIC includes numerous FSPlot commands as in BandWidthPlot.bas. Graph annotations are initially added by the clicking on the graph and manually adding lines and text with the Annotator. The next step is to copy the resulting code to the clipboard via Setup.. Annotations.. Create BASIC Code.

' FSPlot Annotation code for FilmStar BASIC:
PlotClose
PlotAnnotate True
PlotAnnotation = "VERS3" & vbCrLf & _
"vline 1640.001,9,|b 1640.00 nm,16711680;0" & vbCrLf & _
"hline 96.703,9,|l96.70%,16711680;0" & vbCrLf & _
"graph 1633.699,48.352,87,,16711680;0" & vbCrLf & _

Numbers are then replaced by calculated quantities. For example vline 1640.001 is replaced by "vline " & tStr(100*tm) where tm is the maximum transmittance calculated in Sub Bandmax. While this is somewhat tedious it is far easier than creating annotations without the Annotator.

Note that the graph shadow is dark green while the border is light green to match the page color. These are nonstandard FSPlot colors implemented by setting custom Bitmap/Gradient values in Setup.. Graph Details <Ctrl+H>. When publishing graphs it is important to exactly reproduce appearance settings including colors, fonts and graph size. This FSPlot task is accomplished by clicking File.. Create BASIC Code.

' FSPlot graph setup code for FilmStar BASIC:
PlotConfig 8987841, 2129, 0
PlotSize 8505, 6555, 86
PlotTitleFont = "Arial"
PlotTitleSize = 110
PlotLegendSize = 100
PlotLegendSimple = False
' etc

Sample code for setting up FSPlot for different graph types can be found in PlotConfig.bas.

The Interactor connects to FilmStar BASIC via Automation options. A good example is the ability to update an Admittance Smith Chart. Some advanced users have taken advantage of Workbook's ability to run BASIC programs during optimization. This is accomplished by including BasRun or BasExec in Workbook macros.

Links to diverse topics involving FilmStar BASIC:

Copyright © 2023 FTG Software Associates
Last updated on January 31, 2023