OPC Studio User's Guide and Reference
ValueType Property (_UAWriteArgumentsBase)
Example 



OpcLabs.EasyOpcUA Assembly > OpcLabs.EasyOpc.UA.OperationModel.ComTypes Namespace > _UAWriteArgumentsBase Interface : ValueType Property
Specifies the type that should be used when writing the Value attribute.
Syntax
'Declaration
 
<CanBeNullAttribute()>
Property ValueType As Type
'Usage
 
Dim instance As _UAWriteArgumentsBase
Dim value As Type
 
instance.ValueType = value
 
value = instance.ValueType
[CanBeNull()]
Type ValueType {get; set;}
[CanBeNull()]
property Type^ ValueType {
   Type^ get();
   void set (    Type^ value);
}

Property Value

This value of this property can be null (Nothing in Visual Basic).

The default value of this property is null.

The type that should be used when writing the Value attribute.
Remarks

The value of this property is not used when the OpcLabs.EasyOpc.UA.OperationModel.UAAttributeArguments.AttributeId is other than OpcLabs.EasyOpc.UA.UAAttributeId.Value.

A null value in this property means that the component will determine the type of the Value attribute from the DataType and ValueRank attributes of the node first. This can have negative implication on the performance, and introduces a dependency of the value written on the behavior of the OPC server itself.

This member or type is for use from COM. It is not meant to be used from .NET or Python. Refer to the corresponding .NET member or type instead, if you are developing in .NET or Python.

This method or property does not throw any exceptions, aside from execution exceptions such as System.Threading.ThreadAbortException or System.OutOfMemoryException.

Example
// This example shows how to write values into 3 nodes at once, specifying a type explicitly. It tests for success of each 
// write and displays the exception message in case of failure.
//
// Reasons for specifying the type explicitly might be:
// - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
// - The data type that the reports is incorrect.
// - Writing with an explicitly specified type is more efficient.
//
// Alternative ways of specifying the type are using the ValueTypeCode or ValueTypeFullName properties.
//
// Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
// OPC client and subscriber examples in C# on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-CSharp .
// Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
// a commercial license in order to use Online Forums, and we reply to every post.

using System;
using OpcLabs.BaseLib.OperationModel;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class WriteMultipleValues
    {
        public static void ValueType()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object
            var client = new EasyUAClient();

            // Modify value of a node
            OperationResult[] operationResultArray = client.WriteMultipleValues(new[]
                {
                    new UAWriteValueArguments(endpointDescriptor, 
                        "nsu=http://test.org/UA/Data/ ;i=10221", 23456) 
                        {ValueType = typeof(Int32)},    // here is the type explicitly specified
                    new UAWriteValueArguments(endpointDescriptor,
                        "nsu=http://test.org/UA/Data/ ;i=10226", "This string cannot be converted to Double")
                        {ValueType = typeof(Double)},    // here is the type explicitly specified
                    new UAWriteValueArguments(endpointDescriptor,
                        "nsu=http://test.org/UA/Data/ ;s=UnknownNode", "ABC")
                        {ValueType = typeof(string)}    // here is the type explicitly specified
                });

            for (int i = 0; i < operationResultArray.Length; i++)
                if (operationResultArray[i].Succeeded)
                    Console.WriteLine("Result {0}: success", i);
                else
                    Console.WriteLine("Result {0}: {1}", i, operationResultArray[i].Exception.GetBaseException().Message);
        }
    }
}
' This example shows how to write values into 3 nodes at once, specifying a type explicitly. It tests for success of each 
' write and displays the exception message in case of failure.
'
' Reasons for specifying the type explicitly might be:
' - The data type in the server has subtypes, and the client therefore needs to pick the subtype to be written.
' - The data type that the reports is incorrect.
' - Writing with an explicitly specified type is more efficient.
'
' Alternative ways of specifying the type are using the ValueTypeCode or ValueTypeFullName properties.
'
' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html .
' OPC client and subscriber examples in VB.NET on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-VBNET .
' Missing some example? Ask us for it on our Online Forums, https://www.opclabs.com/forum/index ! You do not have to own
' a commercial license in order to use Online Forums, and we reply to every post.

Imports System
Imports OpcLabs.BaseLib.OperationModel
Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Partial Friend Class WriteMultipleValues
        Public Shared Sub ValueType()

            ' Define which server we will work with.
            Dim endpointDescriptor As UAEndpointDescriptor =
                    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
            ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Modify value of a node
            Dim operationResultArray() As OperationResult = client.WriteMultipleValues(New UAWriteValueArguments() _
                { _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;i=10221", 23456) _
                        With {.ValueType = GetType(Int32)}, _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;i=10226", "This string cannot be converted to Double") _
                        With {.ValueType = GetType(Double)}, _
                    New UAWriteValueArguments(endpointDescriptor, _
                        "nsu=http://test.org/UA/Data/ ;s=UnknownNode", "ABC") _
                        With {.ValueType = GetType(String)} _
                } _
             )

            For i As Integer = 0 To operationResultArray.Length - 1
                If operationResultArray(i).Succeeded Then
                    Console.WriteLine("Result {0}: success", i)
                Else
                    Console.WriteLine("Result {0}: {1}", i, operationResultArray(i).Exception.GetBaseException().Message)
                End If
            Next i
        End Sub
    End Class
End Namespace
Requirements

Target Platforms: .NET Framework: Windows 10 (selected versions), Windows 11 (selected versions), Windows Server 2016, Windows Server 2022; .NET: Linux, macOS, Microsoft Windows

See Also