Modifying tagValues using SetValue
Posted: Mon Jul 08, 2013 7:43 am
I want to load values of specific tags back into the panel after exporting a list (tagName,value) and modifying the values.
However i am having troubles with the SetValue function, could you guys point out what i am doing wrong?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.IO;
using Neo.ApplicationFramework.Generated;
using System.Reflection;
using Neo.ApplicationFramework.Tools.OpcClient;
public partial class ImportMenu
{
void LoadSettings(string path)
{
try {
string line;
string tagName;
int tagVal;
using (StreamReader Load = new StreamReader(path))
{
while(( line = Load.ReadLine())!= null)
{
for (int i = 0; i < line.Length; i++)
{
if( line == ',')
{
tagName = line.Substring(0,i);
tagVal = Convert.ToInt16(line.Substring(i+1));
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
PropertyInfo tagProperty =
typeof(Neo.ApplicationFramework.Generated.Tags).GetProperty(tagName);
tagProperty.SetValue(this,tagVal,null);
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
}
}
}
}
MessageBox.Show("Load complete!");
}
catch{
MessageBox.Show("Error while loading");
}
}
However i am having troubles with the SetValue function, could you guys point out what i am doing wrong?
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;
using System.IO;
using Neo.ApplicationFramework.Generated;
using System.Reflection;
using Neo.ApplicationFramework.Tools.OpcClient;
public partial class ImportMenu
{
void LoadSettings(string path)
{
try {
string line;
string tagName;
int tagVal;
using (StreamReader Load = new StreamReader(path))
{
while(( line = Load.ReadLine())!= null)
{
for (int i = 0; i < line.Length; i++)
{
if( line == ',')
{
tagName = line.Substring(0,i);
tagVal = Convert.ToInt16(line.Substring(i+1));
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
PropertyInfo tagProperty =
typeof(Neo.ApplicationFramework.Generated.Tags).GetProperty(tagName);
tagProperty.SetValue(this,tagVal,null);
ListBox1.Items.Add(String.Format("TagName: {0}, Value: {1} loaded", tagName,tagVal));
}
}
}
}
MessageBox.Show("Load complete!");
}
catch{
MessageBox.Show("Error while loading");
}
}