Page 1 of 1

Handling array from scripting

Posted: Tue Aug 04, 2020 11:20 am
by fsturlese
Hello, I am trying to initialize an array into my PLC by means of a script using the following code, launched by a button:
public partial class ScriptModule1
{
public void InitTags()
{
int i;
Globals.Tags.Tag2.Value = 10;
for (i=0; i<10; i++)
Globals.Tags.Tag1.Values.Value = i;
}
}
Tag2 gets intialized with 10, nothing happens to the Tag1 array. Any idea on what I am doing wrong?
Project is attached.
Thanks,
Federico
PerfTestServer.zip
(47.09 KiB) Downloaded 661 times
[/i][/i]

Re: Handling array from scripting

Posted: Thu Aug 06, 2020 8:59 am
by AMitchneck
Hi fsturlese,

You need to access Tag1's value by index. Try the following

Code: Select all

public partial class ScriptModule1
{
  public void InitTags()
  {
    int i;
    Globals.Tags.Tag2.Value = 10;
    for (i=0; i<10; i++)
    {
      Globals.Tags.Tag1.Values[i].Value = i;
    }
  }
}

Re: Handling array from scripting

Posted: Fri Sep 25, 2020 4:18 am
by fsturlese
Thanks Adam