Showing results 1 to 4 of 4

Thread: Accessing variables in Runtime wizard and service

  1. #1
    Join Date
    08.06.2017
    Posts
    3

    Default Accessing variables in Runtime wizard and service

    Hello,

    I have been trying to migrate some of the VSTA functionality to the Add-In Framework for Visual Studio 2017 in Zenon 7.60 but I am not sure how to do this.
    I was looking for the same functionality as it was avaliable in the VSTA to access, read/write by variable name like this:

    Code:
    this.Variables().Item("VariableName").set_Value(vindex, value);

    When I try to implement the same functionality in the Add-In Framework using Developer Tools for VS 2017, I cannot find the "Item" object like the one in the VSTA.
    I'm using the IProject context from the Run or Start methods... 

    Code:
    IVariablesCollection zVariables = context.VariablesCollection;

    And then i vould like to get the Item by the variable name... zVariables.Item("VariableName");... 
    But there is no option to address the variable item by its name. The only method I can see is GetItemById which is not relevant for my use case...
    I also went over all of the examples provided on the github repositories, but I don't find any relevant information about this.

    Can someone please explain what I'm doing wrong... thank you.

  2. #2
    Join Date
    28.02.2013
    Posts
    157

    Default Re: Accessing variables in Runtime wizard and service

    Hello,

    first make sure to add the variable namespace to your project

    using Scada.AddIn.Contracts.Variable;

    then (if you are using Linq) you get the variable object reference from the VariableCollection

    IVariable myVariable = (from X in context.VariableCollection where X.Name == "YOURVARIABLENAME" select X).First();

    to use Linq include also

    using System.Linq;

    Regards,
    Felix

    Quote Originally Posted by emrocon View Post
    Hello,

    I have been trying to migrate some of the VSTA functionality to the Add-In Framework for Visual Studio 2017 in Zenon 7.60 but I am not sure how to do this.
    I was looking for the same functionality as it was avaliable in the VSTA to access, read/write by variable name like this:

    Code:
    this.Variables().Item("VariableName").set_Value(vindex, value);

    When I try to implement the same functionality in the Add-In Framework using Developer Tools for VS 2017, I cannot find the "Item" object like the one in the VSTA.
    I'm using the IProject context from the Run or Start methods... 

    Code:
    IVariablesCollection zVariables = context.VariablesCollection;

    And then i vould like to get the Item by the variable name... zVariables.Item("VariableName");... 
    But there is no option to address the variable item by its name. The only method I can see is GetItemById which is not relevant for my use case...
    I also went over all of the examples provided on the github repositories, but I don't find any relevant information about this.

    Can someone please explain what I'm doing wrong... thank you.


  3. #3
    Join Date
    15.11.2016
    Posts
    97

    Default Re: Accessing variables in Runtime wizard and service

    Hello,

    As Felix mentioned: You need to add some references, if you want to access them directly.
    Like:
    using Scada.AddIn.Contracts.Screen;
    using Scada.AddIn.Contracts.Variable;

    Quote Originally Posted by emrocon View Post
    When I try to implement the same functionality in the Add-In Framework using Developer Tools for VS 2017, I cannot find the "Item" object like the one in the VSTA.

    In the new API there is no "Item" method anymore.

    You can address these objects just with:

    IScreen myScreen = context.ScreenCollection["Screen name"];

    IVariable myVar = context.VariableCollection["Varname"];

    BR,
    Georg
    Last edited by georgk : 13th February 2018 at 09:23

  4. #4
    Join Date
    08.06.2017
    Posts
    3

    Default Re: Accessing variables in Runtime wizard and service

    Thank you both.

    Everything makes sense.
    For some reason my mind was not able to draw parallel between Zenon VariableCollection and C# System.Collections  

    It works now.

Similar Threads

  1. Rename Variables from VBA Wizard
    By yolovs in forum VBA
    Replies: 1
    Last Post: 10th April 2017, 10:01
  2. Replies: 0
    Last Post: 18th May 2015, 14:48
  3. Replies: 1
    Last Post: 19th May 2011, 07:51
  4. Replies: 0
    Last Post: 22nd June 2010, 09:02
  5. Replies: 0
    Last Post: 20th August 2007, 13:08

Posting Rules

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •