I am trying to locate a folder within a Siemens TIA Portal project using a Vb.Net program with Siemens Openness.
If I run the code:
Dim currFolder 'Define the current folder without a type.
currFolder = emptySoftware.BlockGroup
For Each folderName As String In path.Split({"\"}, StringSplitOptions.RemoveEmptyEntries).ToList()
currFolder = currFolder.Groups().Where(Function(x) x.Name = folderName).Single()
Next
I get the error
Public member 'Where' on type 'PlcBlockUserGroupComposition' not found
But the type SW.Blocks.PlcBlockUserGroup
does implement the interface IEnumerable.
Furthermore, if I run the following code:
Dim currFolder 'Define the current folder without a type.
currFolder = emptySoftware.BlockGroup
For Each folderName As String In path.Split({"\"}, StringSplitOptions.RemoveEmptyEntries).ToList()
Dim tmpFolder = CType(currFolder, SW.Blocks.plcBlockGroup)
Dim tmp = tmpFolder.Groups
currFolder = tmpFolder.Groups().Where(Function(x) x.Name = folderName).Single()
Next
I get no error, even though my debugger shows that tmp
is of the type SW.Blocks.PlcBlockUserGroupComposition
Why is this? What makes the second snippet work, where the first one doesn't?
The reason I prefer the first snippet, is because this would enable me to use the same code for different types, which all implement the Groups
attribute, and the Where
function.