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:
Configuring the element Text Editor, example
Drag an element Text Editor into the visualization editor.
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.
For the Text Editor, configure the property with Read only.
Also configure the property
.Assign the following variables there:
with
g_sFileName
with
g_bFileOpen
with
g_bFileClose
with
g_bFileNew
with
g_bFileSave
with
g_sEditSearchFor
with
g_bEditFind
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
Configuring control elements for the file selection
Add an element Label.
Configure the property File:
.
Add an element Rectangle next to it, in which the user can then enter the file name:
Configure the property %s
:
Configure the property g_sFileName
.
Configure the property Write a variable.
withIn 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.
Add an element Button for opening the file.
Configure the property Open
:
Configure the property Toggle a variable.
withAssign
g_bFileOpen
as a variable.
⇒ The button Open
is configured.
Add a further element Button for closing the file.
Configure the property Close
:
Configure the property Toggle a variable.
withAssign
g_bEditFile
as a variable.
⇒ The button Close
is configured.
Control elements for searching for a text.
Add an element Label.
Configure the property Text:
.
Alongside it, add an element Rectangle for the input of the text to be found.
Configure the property %s
:
Configure the property g_sEditSearchFor
.
Configure the property Write a variable.
withIn the dialog Input Configuration, select Text input as the Input type.
Activate the option Use text output variable.
⇒ The rectangle is configured.
Add an element Button for starting the search.
Configure its property Find
.
Configure the property Toggle a variable.
withAssign
g_bEditFind
as a variable.
Also add the action Execute ST-Code.
Program the action with:
g_bEditFindNext := FALSE;
⇒ The button is configured.
Add a further element Button.
Configure the property Find next
.
Configure the property Toggle a variable.
withAssign
g_bEditFind
as a variable.
Also add the action Execute ST code.
Program:
g_bEditFindNext := TRUE;
⇒ The button is configured.
See also