Configuring the Editing of a Text File

In order to be able to create a new text file or edit an existing one on the controller with the text editor in the user interface, you need not only the element Text editor, but also control elements for selecting, opening, closing, saving and creating a file.

Example:

../_images/15e1a2c5f09cdd18c0a8640e001a25c4
  1. Drag an element Text editor into the visualization editor.

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

    Refer below to the declaration of the control variables for this.

  3. For the text editor, configure the property Editing mode with Read/Write.

  4. Also configure the property Control variables.

    Assign the following variables there:

    • Control variables ‣ File ‣ Variable with g_sFileName
    • Control variables ‣ File ‣ Open with g_bFileOpen
    • Control variables ‣ File ‣ Close with g_bFileClose
    • Control variables ‣ File ‣ Save with g_bFileSave
    • Control variables ‣ File ‣ New with g_FileNew

Declaring the 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
  1. Add an element Label.

  2. Configure it in the property Texts ‣ Text with File:.

  3. Add an element Rectangle next to it.

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

  5. Configure its property Texts ‣ Text variable with g_sFileName.

  6. Configure the property Input Configuration ‣ OnMouseclick with Write a variable.

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

    Activate the option Use text output variable.

    The rectangle for the input of the file name is configured.

  7. Add an element Button.

  8. Configure its property Texts ‣ Text with New.

  9. Configure the property Input Configuration ‣ OnMouseclick with Toggle a variable.

    Assign g_bFileNew as a variable.

    The button New is configured.

  10. Add a further element Button.

  11. Configure the property Texts ‣ Text with Open:

  12. Configure the property Input Configuration ‣ OnMouseclick with Toggle a variable.

    Assign g_bFileOpen as a variable.

    The button Open is configured.

  13. Add a further element Button.

  14. Configure its property Texts ‣ Text with Save.

  15. Configure the property Input Configuration ‣ OnMouseclick with Toggle a variable.

    Assign g_bFileSave as a variable.

    The button Save is configured.

  16. Add a further element Button.

  17. Configure its property Texts ‣ Text with Close.

  18. Configure the property Input Configuration ‣ OnMouseclick with Toggle a variable.

    Assign g_bEditFile as a variable.

    The button Close is configured.

See also