Skip to main content

Configuring the display of a text file

To display a text file located on the controller, you need controls for selecting, opening, and closing the file in addition to the Text Editor element. As an option, additional controls can also be used to set up a text search in the file.

Example 16.
_visu_img_display_text_file.png
Procedure. Configuring the Text Editor element, example
  1. Drag a Text Editor element to the visualization editor.

  2. For example, declare the control variables for the element as global variables in the GVL object.

    For more information, see the declaration of the control variables.

  3. For the Text Editor, configure the Editor Mode property with Read Only.

  4. Continue configuring the Control variables property.

    . Assign the following variables there:
    • Control variables → File → Variable: g_sFileName

    • Control variables → File → Open: g_bFileOpen

    • Control variables → File → Close: g_bFileClose

    • Control variables → File → New → Variable: g_bFileNew

    • Control variables → File → Save → Variable: g_bFileSave

    • Control variables → Edit → Variable: g_sEditSearchFor

    • Control variables → Edit → Find: g_bEditFind

    • Control variables → Edit → Find Next: g_bEditFindNext

Declaration of control variables

VAR_GLOBAL
    g_sFileName: STRING := 'Readme.txt';
    g_bFileOpen : BOOL;
    g_bFileClose: BOOL;
    g_bFileNew: BOOL;
    g_bFileSave: BOOL;
    g_sEditSearchFor : STRING;
    g_bEditFind : BOOL;
    g_bEditFindNext : BOOL;
    g_usiErrorHandlingVarForErrorCode: USINT;
    g_bVarForContentChanged : BOOL;
    g_bVarForReadWriteMode: BOOL;
END_VAR
                
Procedure. Configuring control elements for file selection
  1. Add a Label element.

  2. Configure the Texts → Text property with File.

  3. Next to it, add a Rectangle element where the user can then enter the file name:

  4. Configure the Texts → Text property with %s.

  5. Configure the Texts → Text variable property with g_sFileName.

  6. Configure the Input configuration → OnMouseclick property with Write Variable.

    In the Input configuration dialog, select Input type as the Text input.

    Select the Use text output variable option.

    The box to input the file name is configured.

  7. Add a Button property for opening the file.

  8. Configure the Texts → Text property with Open.

  9. Configure the Input configuration → OnMouseclick property with Switch Variable.

    Assign g_bFileOpen as the variable.

    The Open button is configured.

  10. Add another Button button for closing the file.

  11. Configure the Texts → Text property with Close.

  12. Configure the Input configuration → OnMouseclick property with Switch Variable.

    Assign g_bEditFile as the variable.

    The Close button is configured.

Procedure. Controls for searching for a text
  1. Add a Label element.

  2. Configure the Texts → Text property with Text.

  3. Next to it, add a Rectangle element for entering the text to be searched for.

  4. Configure the Texts → Text property with %s.

  5. Configure the Texts → Text variable property with g_sEditSearchFor.

  6. Configure the Input configuration → OnMouseclick property with Write Variable.

    In the Input configuration dialog, select Input type as the Text input.

    Select the Use text output variable option.

    The rectangle is configured.

  7. Add a Button property for starting the search.

  8. Configure its Texts → Text property with Find.

  9. Configure the Input configuration → OnMouseclick property with Switch Variable.

    Assign g_bEditFind as the variable.

  10. Also add the Execute ST code action.

    Program the action with: g_bEditFindNext := FALSE;

    The button is configured.

  11. Add another Button element.

  12. Configure the Texts → Text property with Find Next.

  13. Configure the Input configuration → OnMouseclick property with Switch Variable.

    Assign g_bEditFind as the variable.

  14. Also add the Execute ST code action.

    Program: g_bEditFindNext := TRUE;

    The button is configured.