ValueDialog Function

Help Contents

Introduction

Opens a dialog with a title, a value field and, OK and Cancel buttons.

Syntax

Informal Syntax:

ValueDialog( Title, Prompt, Var )

Formal Syntax:

ValueDialog( Title:=Expression, Prompt:=Expression, Var:=Variable Reference )

Parameters

ParameterTypeDescription
Title ANY_STRING The title that appears at the top of the dialog.
Prompt ANY_STRING The prompt string associated with the text entry field.
Target REF_TO ANY_ELEMENTARY A reference to a program variable.
  • The field is initialized with the value of the program variable when the dialog is opened.
  • The value of the field is written to the program variable when the OK button is pressed.

Return Value

A BOOL value indicating which button was pressed:

ValueButton
FALSECancel
TRUEOK

Remarks

When the Target field is a BOOL value, the dialog creates a check box to represent the field value. For all other types of field, the dialog creates a text entry field to represent the field value.

The ValueDialog() function is logically equivalent to:

FUNCTION ValueDialog : BOOL
VAR_INPUT
    Title : WSTRING;
    Prompt : WSTRING;
END_VAR
VAR_IN_OUT
    Value : ANY_ELEMENTARY;
END_VAR
VAR
    DialogOpenResult : INT;
END_VAR

    DialogNew();
    DialogAddValue( Prompt, Value );
    DialogOpenResult := DialogOpen( Title, 1 );
    ValueDialog := DialogOpenResult <> 0;
END_FUNCTION

Examples

  1. Using ValueDialog with a Digital Data Point Tag:
    VAR V : BOOL; Result : BOOL; END_VAR
    
    (* Read the value of the tag *)
    V:=%"Digital Tag";
    
    (* Open the value dialog to prompt for a new value *)
    Result := ValueDialog( "Pump Control", "Start pump 1", V );
    
    IF Result THEN
    
        (* The user pressed OK, write the new value to the tag *)
        TagWriteValue("Digital Tag", V );
    END_IF;
    

    In the above example, the operator action reads the value of the digital tag "Digital Tag" into variable V. The code then displays the Value Dialog. If the user presses the Cancel button, the Result value will be 0 and the code skips the remaining statements. If the user presses the OK button, the Result value will be 1. The code goes on to write a new value to the digital tag:

    The following image shows the dialog displayed by the preceding code example:

    Value Dialog with a boolean value
  2. Using ValueDialog with an Analog Data Point Tag:
    VAR V : LREAL; Result : BOOL; END_VAR
    
    (* Read the value of the tag *)
    V:=%"Analog Data Point Tag";
    
    (* Open the value dialog to prompt for a new value *)
    Result := ValueDialog( "Change set point", "Enter new set point:", V );
    
    IF Result THEN
    
        (* The user pressed OK, write the new value to the tag *)
        TagWriteValue("Analog Data Point Tag", V );
    END_IF;
    

    In the above example, the operator action reads the value of the analog tag "Analog Data Point Tag" into variable V. The code then displays the Value Dialog. If the user presses the Cancel button, the Result value will be 0 and the code skips the remaining statements. If the user presses the OK button, the Result value will be 1. The code goes on to write a new value to the analog tag:

    The following image shows the dialog displayed by the preceding code example:

    Value Dialog with a real value

Further Information

DialogNew

To learn about the DialogNew() function.

DialogAddTextEditor

To learn about the DialogAddTextEditor() function.

DialogOpen

To learn about the DialogOpen() function.

TagWriteValue()

To learn about the TagWriteValue() function.

Operator Actions

To learn where you can use this function.

Glossary

For the meaning of terms used in Fernhill SCADA.