Using a Script to Display Dialog Boxes

You can use scripts to display dialog boxes when a Mimic item is selected. When you create scripts that display dialog boxes, you may need to use the following:

Example:

The following example shows how a script can be used to display two warning dialog boxes (in sequence) when a Mimic item is selected. The Mimic item represents a water tank and selecting it results in the tank being emptied (after the 2 warning dialog boxes have been displayed). The script is named 'Warning' (as defined in the first line) and is as follows:

Public Function Warning(sMessage, sTankControl)

Dim iResponse

Dim oTankPoint

 

iResponse = MsgBox (sMessage, vbExclamation + vbOKCancel + vbDefaultButton1, "Warning")

 

If iResponse = vbOK Then

iResponse = MsgBox("Are you sure?", vbExclamation + vbYesNo + vbDefaultButton2, "Empty Tank?")

If iResponse = vbYes Then

Set oTankPoint = Server.FindObject(sTankControl)

If Not (oTankPoint Is Nothing) Then

oTankPoint.Interface.Override 1

Warning = 0

Else

MsgBox "Object not found"

Warning = 1

End If

Else

MsgBox "Action Canceled"

Warning = 1

End If

Else

Warning = 1

End If

End Function

The script begins with a Public Function that defines the Warning function and two string values (sMessage and sTankControl).

The script has two variables: iResponse and oTankPoint. The i is used to indicate that the variable is an integer and o is used to indicate that the variable is an object in the database. This is not required, but is regarded as good practice as it allows other users to determine the type of value required for each variable in the script.

The variables are defined as:

Dim iResponse

Dim oTankControl

When the script pick action for the water tank Mimic item is configured, it is associated with the Warning script and the following entry is entered for its value:

"This will empty the tank", "WaterTank.TankMonitorPoint"

When the water tank item is selected on the Mimic, a warning dialog box is displayed. The warning dialog box has a "This will empty the tank" message (defined as the first value in the entry on the Pick Action Wizard. The second entry ("WaterTank.TankMonitorPoint") defines the point on which the override method is performed later in the script.

The warning dialog box has the "This will empty the tank" message and two buttons—OK and Cancel. The warning dialog box and the buttons are defined by the following section of the script:

iResponse = MsgBox (sMessage, vbExclamation + vbOKCancel + vbDefaultButton1, "Warning")

The title of the dialog box is 'Warning'.

This is defined by:

If iResponse = vbOK Then

iResponse = MsgBox("Are you sure?", vbExclamation + vbYesNo + vbDefaultButton2, "Empty Tank?")

 

The second warning dialog box contains the message 'Are You Sure?' and has a Yes and No button. The button that is highlighted by default is the No button (button 2). The title of the warning dialog box is 'Empty Tank?'.

When the Yes button is selected, a method is performed. This is defined by:

If iResponse = vbYes Then

Set oTankPoint = Server.FindObject(sTankControl)

If Not (oTankPoint Is Nothing) Then

oTankPoint.Interface.Override 1

Warning = 0

Else

MsgBox "Object not found"

Warning = 1

End If

 

If the Yes button on the second warning dialog box is selected, the server locates the sTankControl object. The sTankControl object is defined as "WaterTank.TankMonitorPoint" on the Pick Action Wizard (the second value that is entered). If the server can find the point, it performs an override method with a value of 1 and the value of the Warning function is set to 0. The return value of the Warning function can be used by other scripts.

If the server cannot locate the sTankControl object, the script sets the value of the oTankPoint variable to null and a message box is displayed. The message box contains the message "Object not found". If the object cannot be found, the value of the Warning function is set to 1.

When the No button is selected on the second warning dialog box, another message dialog box is displayed. The message dialog box is an information dialog box and has the title and message 'Action Canceled'. If the action is canceled, the value of the Warning function is set to 1.

This is defined by the following section of the script:

Else

MsgBox "Action Canceled"

Warning = 1

End If

If the Cancel button is selected on the first warning dialog box, the dialog box is closed. This is defined by the last part of the script:

Else

Warning = 1

End If


Disclaimer

Geo SCADA Expert 2022