Configuring the Display of a Text File

In order to display a text file that is located on the controller, you need not only the element Text editor, but also control elements for selecting, opening and closing the file. Optionally a text search function can be set up in the file with further control elements.

Example:

../_images/34eb4cc1f04ac572c0a8640e011002ad
  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 to the declaration of the control variables for this.

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

  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 ‣ New ‣ Variable with g_bFileNew
    • Control variables ‣ File ‣ Save ‣ Variable with g_bFileSave
    • Control variables ‣ Edit ‣ Variable with g_sEditSearchFor
    • Control variables ‣ Edit ‣ Find with g_bEditFind
    • Control variables ‣ Edit ‣ Find next occurrence with g_bEditFindNext

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

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

  3. Add an element Rectangle next to it, in which the user can then enter the file name:

  4. Configure the property Texts ‣ Text with %s:

  5. Configure the 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 for opening the file.

  8. Configure the property Texts ‣ Text with Open:

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

    Assign g_bFileOpen as a variable.

    The button Open is configured.

  10. Add a further element Button for closing the file.

  11. Configure the property Texts ‣ Text with Close:

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

    Assign g_bEditFile as a variable.

    The button Close is configured.

  1. Add an element Label.

  2. Configure the property Texts ‣ Text with Text:.

  3. Alongside it, add an element Rectangle for the input of the text to be found.

  4. Configure the property Texts ‣ Text with %s:

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

  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 is configured.

  7. Add an element Button for starting the search.

  8. Configure its property Texts ‣ Text with Find.

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

    Assign g_bEditFind as a variable.

  10. Also add the action Execute ST-Code.

    Program the action with: g_bEditFindNext := FALSE;

    The button is configured.

  11. Add a further element Button.

  12. Configure the property Texts ‣ Text with Find next.

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

    Assign g_bEditFind as a variable.

  14. Also add the action Execute ST-Code.

    Program: g_bEditFindNext := TRUE;

    The button is configured.

See also