HCBBS Forum (English)
Submit Chemical Projects / Find Solutions
Amplify Your Requirements on a Broader Chemical Platform *Engineering · Technology · Equipment · Solutions*
Submit Request

Wincc Script Example 3 – Sorting Records in the MSHFGrid Control by Fields

2016-04-16View Original

Thread Content

Sometimes we also need to enable operators to sort by fields after clicking on the MSHFGrid control; this article explains how to achieve this functionality. 1. Preparation: Create a new internal variable of 32-bit floating-point type named Sort in Wincc, to indicate whether the sorting should be in ascending or descending order. Insert a static text element on the WinCC page; rename it to “txt”. Set its Property – Effects – Global Color to “No”. For the Property – Color – Background Color, set the transparency to 100 and the border thickness to 0.

For the sorting script, enter the following code in the MSHFGrid control’s event – Object Events – MouseUp:
Dim MSHFGrid, txt, sort
Set MSHFGrid = ScreenItems(“MSHFGrid”)
Set sort = HMIRuntime.Tags(“Sort”)
Set txt = ScreenItems(“txt”)

If MSHFGrid.TextMatrix(0, item.MouseCol) = “Date and Time” Then
If sort.Read = 2 Then
MSHFGrid.Sort = 1 ‘Sort in ascending numerical order
sort.Write 1
txt.Text = “Currently sorted in ascending order based on the “ & MSHFGrid.TextMatrix(0, item.MouseCol) & “ field.”
Else
MSHFGrid.Sort = 2 ‘Sort in descending numerical order
sort.Write 2
txt.Text = “Currently sorted in descending order based on the “ & MSHFGrid.TextMatrix(0, item.MouseCol) & “ field.”
End If
Else If sort.Read = 2 Then
MSHFGrid.Sort = 5 ‘Sort in ascending alphabetical order
sort.Write 1
txt.Text = “Currently sorted in ascending order based on the “ & MSHFGrid.TextMatrix(0, item.MouseCol) & “ field.”
Else
MSHFGrid.Sort = 6 ‘Sort in descending alphabetical order
sort.Write 2
txt.Text = “Currently sorted in descending order based on the “ & MSHFGrid.TextMatrix(0, item.MouseCol) & “ field.”
End If
End Sub

Save and run the script to see the result. This script is based on the project from the previous blog post. For information on how to connect MSHFGrid to a database, please refer to other posts that provide recommendations for WinCC scripts.
Reply #22016-04-17
Can I upload a packaged file?

Submit a Project

**Looking for Chemical Technology, Equipment & Solutions?** No Registration Required Broader Platform Exposure | Global Chemical Service Provider Connections

Submit Request — Free Consultation

Disclaimer

This is an automated machine translation of the original thread. Some technical terms may have inaccuracies; the original text shall prevail. Click "View Original" at the top right to access the source page, which supports IP-based automatic real-time language translation. Please watch out for contact details and sales inducements to prevent fraud. All content and translations are for reference only, representing solely the poster's personal views. For enquiries, email service@hcbbs.com.