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:
Drag an element Text editor into the visualization editor.
Declare the control variables for the element, for example as global variables in the
GVLobject.- ⇒
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
- with
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
Add an element Label.
Configure the property with
File:.Add an element Rectangle next to it, in which the user can then enter the file name:
Configure the property with
%s:Configure the property with
g_sFileName.Configure the property 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.
Add an element Button for opening the file.
Configure the property with
Open:Configure the property with Toggle a variable.
Assign
g_bFileOpenas a variable.- ⇒
The button
Openis configured.
Add a further element Button for closing the file.
Configure the property with
Close:Configure the property with Toggle a variable.
Assign
g_bEditFileas a variable.- ⇒
The button
Closeis configured.
Add an element Label.
Configure the property with
Text:.Alongside it, add an element Rectangle for the input of the text to be found.
Configure the property with
%s:Configure the property with
g_sEditSearchFor.Configure the property 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.
Add an element Button for starting the search.
Configure its property with
Find.Configure the property with Toggle a variable.
Assign
g_bEditFindas 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 with
Find next.Configure the property with Toggle a variable.
Assign
g_bEditFindas a variable.Also add the action Execute ST-Code.
Program:
g_bEditFindNext := TRUE;- ⇒
The button is configured.
See also