Features, discussions, tips, tricks, questions, problems and feedback

How to update elements using C# or VB / Set the values of tags

try
  {
     DataElement de1 = DataElementEngine.NewDataElement("Adroit.A1.value");
     de1.Value = 3.14;  
     DataElement de2 = DataElementEngine.NewDataElement("Adroit.A2.value");
     de2.Value = 42; //<-- this could be retrieved from other controls on the form as well
     DataElementCollection dec = DataElementEngine.NewDataElementCollection();
     dec.Add(de1);
     dec.Add(de2);
     MethodReturnInfo info = MyConnection.UpdateDataElements(dec);
     if (!info.Success)
     {
        MessageBox.Show("An error occurred whilst updating the value, the error was: " + info.ReturnInformation);
     }
  }
  catch (Exception ex)
  {
     MessageBox.Show("An error occurred: " + ex.ToString());
  }

Similar code but in VB:

    Dim de As DataElement = DataElements.Engine.DataElementEngine.NewDataElement("Adroit._SAMPLEEXPRESSION.v01")
    de.Value = 0

    Dim dec As DataElementCollection = DataElements.Engine.DataElementEngine.NewDataElementCollection()
    dec.Add(de)

    Dim info As MethodReturnInfo = MyConnection.UpdateDataElements(dec)
    If info.Success Then
        MessageBox.Show("Update of Adroit._SAMPLEEXPRESSION.v01 was successfull")
    Else
        MessageBox.Show("Update of Adroit._SAMPLEEXPRESSION.v01 has failed: " + info.ReturnInformation)
    End If