Reading aspect properties from VBA script
Trying to make a VBA Script so I can get a list of all connected tags to each io-card in a 800xA sv5.0 system.
Here is a part of the code that do not work:
The properties.count gets the value 0 so this code does not work.
When I remove FOR y =.... the error codes I get is as commented behind the lines below:
Dim x As Integer
Dim y As Integer
For x = 0 To sc.Children(i).object.Aspects.count - 1
If sc.Children(i).object.Aspects.Aspect(x).Name = "Control Properties" Then
For y = 0 To sc.Children(i).object.Aspects.Aspect(x).Properties.count - 1
Debug.Print sc.Children(i).object.Aspects.Aspect(1).Properties(y).Name 'getting error message "invalid procedure call or argunent"
Debug.Print sc.Children(i).object.Aspects.Aspect(x).Properties.Property(y).Name '![1_Var_Conn] 'getting error message "invalid procedure call or argunent"
Debug.Print sc.Children(i).object.Aspects.Aspect(x).Properties("1_Var_Conn").Value 'getting error message "invalid procedure call or argunent"
Next y
End If
Next x
Next i
See attached screenshot showing what I want to fetch.
Where can I find examples so i can solve this?
Answers
It's correct what you get for the Properties.Count, because the "Properties" as per your screenshot are not actually OPC Properties of the Aspect but part of the Datablob. The Properties you get via Aspect.Properties are the ones found under "Details..." Option in Context Menu - Property View.
You'll need to find the correct Interface via the Implementation Binding to get the Properties Data as per your Screenshot - sorry that i can't help you further.
Your code is very inefficient and will take a long time to execute because you are forcing it to search every aspect in the entire system. The objects can be accessed much more eficiently if you treat them as "collections". (All the objects are already typed so you dont need to create a "New Collection".)
Use the "For Each" syntax, not "for i=0 to n-1". That way you do not need loop counters or the Object.Count or object.aspect.count properties.
Use the Object.Aspect("Control Properties") syntax to directly access the control properties aspect instead of searching for it.
You can reduce the size of the search by starting at Object.Name("Your controller")
Another way of getting this information is to go into "test" mode in control builder and then print the documentation for the hardware structure. You can then extract the data from the resulting Word Document
Fianlly, for me, I find that breaking the code execution in the middle of the for loop and then using the "immediate" window to execute VBA commands is more effective than a lot of debug.prints
Add new comment