1

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.

braX
  • 11,506
  • 5
  • 20
  • 33
DrDonut
  • 864
  • 14
  • 26
  • @MatSnow You are right, the answer describes very nicely what I need (couldn't find it earlier). Should I close this question? – DrDonut Dec 21 '17 at 10:40

0 Answers0