Skip to main content

Configuring the editing of a text file

To use the Text Editor in the user interface to create or edit a text file on the controller, you need controls for selecting, opening, closing, saving, and creating a file in addition to the Text Editor element.

Example:

_visu_img_edit_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 below.

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

  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 → Save: g_bFileSave

    • Control variables → File → New: g_FileNew

Declaration of control variables

VAR_GLOBAL
    g_sFileName: STRING := 'Readme.txt';
    g_bFileOpen : BOOL;
    g_bFileClose: BOOL;
    g_bFileSave: BOOL;
    g_FileNew: 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 it in the Texts → Text property with File.

  3. Add a Rectangle element next to it.

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

  5. Configure its 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 element.

  8. Configure its Texts → Text property with New.

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

    Assign g_bFileNew as the variable.

    The New button is configured.

  10. Add another Button element.

  11. Configure the Texts → Text property with Open.

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

    Assign g_bFileOpen as the variable.

    The Open button is configured.

  13. Add another Button element.

  14. Configure its Texts → Text property with Save.

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

    Assign g_bFileSave as the variable.

    The Save button is configured.

  16. Add another Button element.

  17. Configure its Texts → Text property with Close.

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

    Assign g_bEditFile as the variable.

    The Close button is configured.