Welcome Guest ( Login | Register )



All times are UTC - 7 hours [ DST ]



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

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

Offline
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


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

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

Offline
See answer from AMitchneck

viewtopic.php?f=6&t=2029


 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 7 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron