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.

Drag a Text Editor element to the visualization editor.
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.
For the Text Editor, configure the property with Read Only.
Continue configuring the
property.. Assign the following variables there:
:g_sFileName
:g_bFileOpen
:g_bFileClose
:g_bFileNew
:g_bFileSave
:g_sEditSearchFor
:g_bEditFind
: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
Add a Label element.
Configure the
property withFile
.Next to it, add a Rectangle element where the user can then enter the file name:
Configure the
property with%s
.Configure the
property withg_sFileName
.Configure the Write Variable.
property withIn 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.
Add a Button property for opening the file.
Configure the
property withOpen
.Configure the Switch Variable.
property withAssign
g_bFileOpen
as the variable.The
Open
button is configured.Add another Button button for closing the file.
Configure the
property withClose
.Configure the Switch Variable.
property withAssign
g_bEditFile
as the variable.The
Close
button is configured.
Add a Label element.
Configure the
property withText
.Next to it, add a Rectangle element for entering the text to be searched for.
Configure the
property with%s
.Configure the
property withg_sEditSearchFor
.Configure the Write Variable.
property withIn the Input configuration dialog, select Input type as the Text input.
Select the Use text output variable option.
The rectangle is configured.
Add a Button property for starting the search.
Configure its
property withFind
.Configure the Switch Variable.
property withAssign
g_bEditFind
as the variable.Also add the Execute ST code action.
Program the action with:
g_bEditFindNext := FALSE;
The button is configured.
Add another Button element.
Configure the
property withFind Next
.Configure the Switch Variable.
property withAssign
g_bEditFind
as the variable.Also add the Execute ST code action.
Program:
g_bEditFindNext := TRUE;
The button is configured.