KB-31734: Using Validate event.

Question:

What is the Validate event’s purpose? How can I use it?

Solution:

You use this event to validate the input data, allowing you to cancel the operation if the received data is not as good as you expected. Validate event is executed after typing data on the setpointand before data is passed to the linked tag. 

For example, suppose there is a setpoint linked to a tag that must receive a time value in the HHMM format (as integer) and you want to validate the minutes (MM) that are not higher than 59. NewValue parameter receives the typed value, and Cancel parameter, if set to True, cancels the operation.

The script below validates the information typed on the minutes and checks if it is higher than 59. If so, Cancel parameter is set to True and the typed data is not passed to the tag linked to the setpoint.


Sub Text1_Validate(Cancel, NewValue)
    Minutes = Mid(NewValue, 3, 2)

    If Minutes > 59 Then
        Cancel = TRUE
    End If
End Sub

Print Friendly, PDF & Email

Este artigo foi útil? Was this helpful?

Classificação média - Average rating 0 / 5. Count: 0

Leave a Reply

Your email address will not be published.Required fields are marked *