Script in reports allows you to freely customize the calculations on the database data. Statistics, certificates, quality reports (ISO), etc.
(To understand the script in the SCADA software: Script – Introduction – Step 1)
(To understand how to generate a report: Create a report )
How to access the report script in the LAquis SCADA
Stop the application if it is running, open the report and click on the Edit button:
The report will be in the Edit mode. Then the events and the script will be available in the right side of the window.
The main most used events are:
OnAfterCalculation: after all data read from database and calculated. Generally used to calculate new results from the data.
OnAfterOpen: shortly after the report is opened. Generally used to set default parameters in cells (date, group, ID, tag, etc…).
OnAfterListing: after all data read from database but before calculation and chart. Generally used to calculate and change or create new data.
OnClick: when a user click on a cell or button. Generally used to calculate, open or save specific data.
OnText: change the print text of a cell.
Script specific commands of the spreadsheet report:
2 main common examples:
1 – Example on the event OnAfterCalculation or OnAfterListing. Easily accessing data directly from the table of the database and calculating a generic result:
n = ldbcount ‘ ldbcount is the number of registers of the main database table
x = 0
if n > 0 then
for i=1 to n
x1=LdbCellN(“TAG1”,i) ‘ LdbCellN read or write the value of the field/tag/column of the database table
if x1>7 then
x = x + x1*x1
end if
next
x = x / n
end if
cellsNname(“RESULT”)= x ‘ cellsNname reads or writes the value in a cell based on the associated name.
2 – Example on the event OnAfterOpen. Setting the default parameters to the report:
cellsnname(“DATE”)=int(now) ‘ set the “date” cell as the current date
s=“”
s=tags.CurrentRowGroup ‘ get the current selected group
if len(s)=0 then
s=“*”
end if
cellsname(“GROUP”)=s ‘ set the “group” cell as the current selected group
Click the button F4 to get the list of available commands.
Main commands to access the report spreadsheet:
cells(column,row): read or write a text value in the report spreadsheet based on the column and row.
cellsN(column,row): read or write a number value in the report spreadsheet based on the column and row.
cellsname(name): read or write a text value in the report spreadsheet based on the associated name of the cell.
cellsNname(name): read or write a number value in the report spreadsheet based on the associated name of the cell.
Example:
x = cellsN(3,5) ‘ cellsN reads or writes the value of a cell as a number
cellsN(7,3) = x
s = “”
s = cells(12,13) ‘ cells reads or writes the value of a cell as a text
Database table commands:
LdbCount: retunrs number of registers of the main database table.
LdbCellN(field name,register number): read or write the number value of the main database table based on the field name/column/tag and the specific register number. The register number is from 1 to ldbcount.
LdbCell(field name,register number): the same of LdbCellN but as text.
LdbThisLine(register number): returns the real row/line of the report spreadsheet cell based on the specific register number. The register number is from 1 to ldbcount.
ColumnName(fieldname number): number of registers of the main database table.