Welcome to the new Schneider Electric Community

It's your place to connect with experts and peers, get continuous support, and share knowledge.

  • Explore the new navigation for even easier access to your community.
  • Bookmark and use our new, easy-to-remember address (community.se.com).
  • Get ready for more content and an improved experience.

Contact SchneiderCommunity.Support@se.com if you have any questions.

Close
Invite a Co-worker
Send a co-worker an invite to the Exchange portal.Just enter their email address and we’ll connect them to register. After joining, they will belong to the same company.
Send Invite Cancel
84248members
353348posts

Passing array into a script

EcoStruxure Geo SCADA Expert Forum

Find out how SCADA systems and networks, like EcoStruxure Geo SCADA Expert, help industrial organizations maintaining efficiency, processing data for smarter decision making with IoT, RTU and PLC devices.

Solved
IgorSivakov
Lieutenant
Lieutenant
0 Likes
4
834

Passing array into a script

I try to pass an array from project database to script. I can read it and write to another array, but when I try access an an array element, I get an error message about inconsistent data types.

 

public function ArrayTest (A)
dim i, N(5),
for i = 1 to 3
N(i) = 0
N(i) = A(i)
next
end function

 

 

Accepted Solutions
AdamWoodland
Commander Commander
Commander
0 Likes
3
829

Re: Passing array into a script

Are you sure the variable A is an array? And the array is big enough for all those elements? You'd get that sort of error if it weren't. I just took your code and put some code around it to read the array from an Long Array variable in the database and it works on my machine so feel free to tweak as necessary

 

Option Explicit

Public Sub RunMe

Dim O
Set O = Server.FindObject("Array Test.Long Array")
If O Is Nothing Then
MsgBox("Not found")
Exit Sub
End If

Dim X
X = O.Interface.Value
ArrayTest(X)
End Sub

Public Function ArrayTest(A)
Dim i, N(5)
For i = 1 To 3
N(i) = 0
N(i) = A(i)
Next
ArrayTest = 0
End Function

Just make sure you set some values to the database object (i.e. write a value to element 10 to populate the array by clicking on the object in the sidebar and choosing Set Element). The code is also missing some validation checks so not "production ready"

See Answer In Context

4 Replies 4
AdamWoodland
Commander Commander
Commander
0 Likes
3
830

Re: Passing array into a script

Are you sure the variable A is an array? And the array is big enough for all those elements? You'd get that sort of error if it weren't. I just took your code and put some code around it to read the array from an Long Array variable in the database and it works on my machine so feel free to tweak as necessary

 

Option Explicit

Public Sub RunMe

Dim O
Set O = Server.FindObject("Array Test.Long Array")
If O Is Nothing Then
MsgBox("Not found")
Exit Sub
End If

Dim X
X = O.Interface.Value
ArrayTest(X)
End Sub

Public Function ArrayTest(A)
Dim i, N(5)
For i = 1 To 3
N(i) = 0
N(i) = A(i)
Next
ArrayTest = 0
End Function

Just make sure you set some values to the database object (i.e. write a value to element 10 to populate the array by clicking on the object in the sidebar and choosing Set Element). The code is also missing some validation checks so not "production ready"

IgorSivakov
Lieutenant
Lieutenant
0 Likes
2
824

Re: Passing array into a script

Yes, A is an array, I can see it in debug mode. And size of A an N is the same (I tried to make N bigger and it doesn't work either). It works as you suggested, so I should just go your way. But now I'm just curiouis about it. I tried to pass object as an argument (second screenshot), just .Value, .ValueFormatted and .ValueReadOnly and it dostn't work anyway

debug.JPG

изображение_2021-05-06_095725.png

AdamWoodland
Commander Commander
Commander
0 Likes
1
804

Re: Passing array into a script

Interesting. I'd suggest it is a bug somewhere in the product and you need to raise it to support formally for an answer.

 

Put the following as the first bit of code in the ArrayTest function

 

MsgBox(TypeName(A))

 

When ran from my code it shows it is an array of variants, but when called directly from a pick action its an array of longs. The array N is variant so it seems to be unhappy with the type conversion from long to variant (which is probably more VBScript's fault?). I would have thought using CVar would work but its still not happy and I can't currently find a solution. e.g. the following should work in my head:

 

N(i) = CVar(A(i))

 

Support may have seen this before and have a solution I don't know about.

 

 

IgorSivakov
Lieutenant
Lieutenant
0 Likes
0
796

Re: Passing array into a script

Thanks for the answers. As soon as SE Russia can actially sell us license for tech support (we can't buy it for months now), I'll ask them and update this topic.