EcoStruxure Geo SCADA Expert Forum
Schneider Electric support forum about installation, configuration, integration and troubleshooting of EcoStruxure Geo SCADA Expert (ClearSCADA, ViewX, WebX).
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 10:08 PM . Last Modified: 2023-05-03 12:03 AM
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
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 10:32 PM . Last Modified: 2021-05-05 10:34 PM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 10:32 PM . Last Modified: 2021-05-05 10:34 PM
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"
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 10:32 PM . Last Modified: 2021-05-05 10:34 PM
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 10:32 PM . Last Modified: 2021-05-05 10:34 PM
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"
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-05 11:58 PM
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
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-06 03:15 PM
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.
Link copied. Please paste this link to share this article on your social media post.
Link copied. Please paste this link to share this article on your social media post.
Posted: 2021-05-06 10:16 PM
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.
Link copied. Please paste this link to share this article on your social media post.
Create your free account or log in to subscribe to the board - and gain access to more than 10,000+ support articles along with insights from experts and peers.