iX Talk
http://beijerinc.com/support/ix/forum/

Don't work - FAQ: How to convert a string to a Screen or Tag
http://beijerinc.com/support/ix/forum/viewtopic.php?f=17&t=2045
Page 1 of 1

Author:  andis59 [ Thu Feb 25, 2016 2:36 am ]
Post subject:  Don't work - FAQ: How to convert a string to a Screen or Tag

I have tried to use the code from the FAQ: How to convert a string to a Screen or Tag, but I can't get it to work...

First the GlobalDataItem is not found so this is needed
using Neo.ApplicationFramework.Tools.OpcClient;

But then it will not find my tag!?

I have added the StringToTag function
Code:
public GlobalDataItem StringToTag(string tagName)
{
   string typeName = (new GlobalDataItem()).GetType().Name;
   PropertyInfo[] props = Globals.Tags.GetType().GetProperties();
   foreach (PropertyInfo prop in props) {
      if (prop.PropertyType.Name.Equals(typeName)) {
         if (prop.Name.Equals(tagName, StringComparison.CurrentCultureIgnoreCase)) {
            return (GlobalDataItem)prop.GetValue(Globals.Tags, null);
         }               
      }
   }
   return null;
}


My code looks like this:
Code:
void Button_Click(System.Object sender, System.EventArgs e)
{
   GlobalDataItem tag = StringToTag("ShutterNotOpen");
   if(tag!=null)
   {
      tag.Value = "Hello World";
   }
   else
   {
      MessageBox.Show("Can't find Tag");
   }
}


NB! The Tag exists!

But the StringToTag always returns null

I'm using iX Developer version 2.20

Anyone knows why and how to fix this???

// Anders

Author:  andis59 [ Wed Mar 09, 2016 1:15 am ]
Post subject:  Re: Don't work - FAQ: How to convert a string to a Screen or

See answer from AMitchneck

viewtopic.php?f=6&t=2029

Page 1 of 1 All times are UTC - 7 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/