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

Post Reply
andis59
Posts: 13
Joined: Mon Apr 08, 2013 11:50 am

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

Post 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

andis59
Posts: 13
Joined: Mon Apr 08, 2013 11:50 am

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

Post by andis59 »


Post Reply