1

I'm trying to make TreeView from XML file but there is an error after validation (in bold line): "not an array or indexer".

dim NavBarPath as string;

dim xDoc as System.Xml.XmlDocument;

dim fs as System.IO.FileStream;

dim xRoot as System.Xml.XmlElement;

dim xnode as System.Xml.XmlNode;

dim rootnode as System.Windows.Forms.TreeNode;

NavBarPath = InTouch:InTAppDir + "NavBar.xml";

xDoc = new System.Xml.XmlDocument();

fs = new System.IO.FileStream(NavBarPath, FileMode.Open, FileAccess.Read);

xDoc.Load(fs);

xRoot = xDoc.DocumentElement;

for each xnode in xRoot

rootnode = new System.Windows.Forms.TreeNode(xnode.Attributes["Name"].Value);

...

next;

Mike K
  • 63
  • 1
  • 7
  • Can you share a copy of `NavBar.xml`? I'm toying around with the code and can't replicate the issue. I'm wondering if Wonderware just hates that formatting. I'm assuming this is all in an ArchestrA graphic script? What version wonderware? – Grambot Jan 15 '21 at 16:49
  • 1
    Yes, it's all in Archestra Graphic scripting and this error appear when I click on red "validate" button, so I think it's doesn't matter what the structure of file is. There is something wrong with syntax and coding in Archestra is really true adventure, especially in using .NET. I do the same in Visual Studio (C#) and everything worked fine. I use IDE 3.1 – Mike K Jan 16 '21 at 17:25
  • 1
    I assumed some functions just not realised (like "try-catch" e.g.) – Mike K Jan 16 '21 at 17:33
  • 1
    Yeah I think it just boils down to the scripting not using the array access that you get in VB or C# .NET programs. Would changing it from `xnode.Attributes["Name"].Value` to `xnode.Item["Name"].Value` work? The other way I tried is creating a `XmlAttributeCollection` variable, assigning `xnode.Attributes` to it then accessing via `attribute_collection_variable.GetNamedItem("Name").Value`. The validation doesn't complain anymore, but no idea if it works – Grambot Jan 18 '21 at 19:53
  • And partially unrelated, from ArchestrA 2017 onward they have a bastardized try-catch which has come in handy.... `try ... catch LogError(error); endtry;` – Grambot Jan 18 '21 at 19:54
  • 1
    Bingo! XmlAttributeCollection - it's worked! Thanks a lot! – Mike K Jan 20 '21 at 04:49

0 Answers0