1. Home
  2. Custom menus example – Transformations

Custom menus example – Transformations

This example demonstrates how to create a custom dialog to produce a simple transformation of a variate. In this example we will create a dialog with an associated user procedure called TRNSFRM. The procedure performs a simple transformation on a variate allowing the results to be saved and displayed in a spreadsheet. The dialog produced by this example is shown below:

Resource language

The following code (transform.grc) shows the resource language to create the dialog and its controls.

DIALOG DIALOG_TRANSFORM,210, 208
CAPTION “Transformation example dialog”
PROCEDURE “TRNSFRM”
BEGIN
   PUSHBUTTON “&Run”,IDRUN,32, 188, 54, 14,BS_RUN
   PUSHBUTTON “&Cancel”,IDCANCEL,90,188,54,14,BS_CANCEL
   PUSHBUTTON “&Help”,IDHELP,148, 188, 54, 14, BS_HELP, “transform.html”
   LTEXT “&Available data:”,ITEXT,2,2,52,9
   LISTBOX IDLIST,2,12,90,120,GW_AVAILABLE
   LTEXT “&Data:”,ISTATIC,100,6,46,9
   EDITTEXT X,100,16,100,14,GW_AVAILABLE | DT_TYPVAR | GW_PARAM | EC_SET
   LTEXT “&Save in:”,ISTATIC,100,36,46,9
   EDITTEXT NEWX,100,46,100,14,GW_AVAILABLE | DT_TYPVAR | GW_PARAM | EC_SET
   LTEXT “&Transformation:”,ISTATIC,100,64,70,9
   COMBOBOX TRANSFORM,100,74,90,64,CB_DROPLIST | GW_OPT
   SLIST TRANSFORM,”Log (base e)”,”Log (base 10)”,”Logit”
   RLIST TRANSFORM,”log”,”log10″,”logit”
   LTEXT “&Inverse transformation:”,ISTATIC,100,92,100,9
   RADIOBUTTON “Yes”, INVERSE, 108, 102, 40, 14, GW_OPT, “yes”
   RADIOBUTTON “No”, INVERSE, 150, 102, 40, 14, GW_OPT | GW_SEL, “no”
   GROUPBOX “Display”, IDSTATIC, 100, 120, 100, 46
   CHECKBOX “&Minimum”,PRINT,104,130,70,14,GW_OPT | GW_SEL,”min”
   CHECKBOX “Ma&ximum”,PRINT,104,146,70,14,GW_OPT | GW_SEL,”max”
   TOGGLEBOX “Dis&play data in spreadsheet”,SPREADSHEET,80,170,130,14,GW_OPT,”yes”,”no”
END

The dialog contains two edit controls providing the user with a space to specify the variate to transform and the name of a variate to store the results within. A combo box is used to allow a list of possible transformations; there are three possible transformations in the procedure TRNSFRM. The procedure TRNSFRM includes an option to specify whether the transformation is an inverse transformation. On the dialog two radio buttons are used with the matching option ID called INVERSE to retrieve the user’s choice (yes or no). The procedure allows a list of print options to display the min, max or both for the transformed values. The dialog has two check boxes within a group box that are linked to the procedure option name PRINT by using the same ID as the option.

A toggle box is used to represent the SPREADSHEET option of the TRNSFRM procedure where it returns yes or no depending on whether the check box has been set or not. There is Help for the dialog, which is stored in the file transform.html. To associate this with the dialog a Help push button is included using BS_HELP. In the statement for the Help button the file containing the Help has been supplied as the last argument. The dialog is also given a run button using the BS_RUN flag. When the Run button is clicked it will form a Genstat command using the TRNSFRM procedure and submit the command to the server. The ‘&’ character is used in text for the controls to specify mnemonic characters for the dialog.

Attaching to Genstat

To attach a custom dialog menu add-in to Genstat you must supply the details within a Genstat add-in (GAD) file. The type of add-in, in this case the dialog, should be supplied using a subsection called Type. You must supply the add-in using the dialog ID used in the resource file (DIALOG1) using the ProgID subsection. Supply the name that is to appear on the User menu using the subsection MenuTitle. Enter the name of the file containing the dialog resources (transform.grc) entered using the subsection ResourceFile. You must supply the full path with the resource filename, unless the resource file is contained in the same folder as the GAD file. The following example shows the layout required to attach the dialog.

[AddIn1]
    Type=DIALOG
    ProgID=DIALOG_TRANSFORM
    MenuTitle=Transformation dialog example
    ResourceFile=transform.grc

To make the add-ins accessible from Genstat save the GAD file using the file extension .gad, for example, transform.gad. Copy the file to either the system or user add-in directory. The next time you start Genstat the custom dialog should attach automatically and the menu item to open the dialog will be found under the User menu.

Running the example

The files for this example can be found in the CustomMenus folder within the Examples folder in the Genstat installation (the default installation location will be C:\Program Files\GenxxEd\Examples\CustomMenus).

transform.gpi Source code for procedure called TRNSFRM
transform.glb Procedure library containing the procedure TRNSFRM
transform.gad GAD file for attaching the transformation custom dialog
transform.grc Genstat resource file containing source for transformation custom dialog
transform.html HTML Help file for the transformation custom dialog

To run the example copy the files transform.glb, transform.gad, transform.grc and transform.html to either your user or system add-in folder and start Genstat. When you start Genstat a new menu item should appear under the User menu called Transform Data Example.

To uninstall the custom dialog example, close Genstat then remove the four files from the add-in directory.

See also

Updated on June 20, 2019

Was this article helpful?