Page 1 of 1

Don't work - FAQ: How to convert a string to a Screen or Tag

Posted: Thu Feb 25, 2016 2:36 am
by andis59
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: Select all

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: Select all

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

Re: Don't work - FAQ: How to convert a string to a Screen or

Posted: Wed Mar 09, 2016 1:15 am
by andis59