私はまだ(C ++の)初心者プログラマーであり、実行中のソフトウェアからのタグを表示するGIUを作成しています。目的は、タグのプロパティDescription
とを表示することですEng Units
。私は2つのdllInTouchDataAccessとNDdeを与えられました。私は例外処理について読みましたが、私が見た中で最も良いアイデアはこれでした:
検証関数を作成する
私がやった。しかし、プログラムは関数に入りません。私は自分のSelectButton_Click
fctのcatchブロックにまっすぐ入ります。
TagBrowser.cs
using System;
using System.Windows.Forms;
using IOM.InTouchDataAccess;
namespace InTouchTagBrowser
{
public partial class InTouchTagBrowser : Form
{
public string tagName;
public string description;
public string engUnits;
public InTouchTagBrowser()
{
InitializeComponent();
}
private void TagBrowser_Load(object sender, EventArgs e)
{
}
private void SelectButton_Click(object sender, EventArgs e)
{
try
{
tagName = tagNameBox.Text;
InTouchDdeWrapper inTouchWrapper = new InTouchDdeWrapper();
inTouchWrapper.Initialize();
TagDotField tagDotField = new TagDotField(tagName);
string value = inTouchWrapper.Read(tagName);
if (EngValidate(inTouchWrapper.Read(tagDotField.EngUnits)) != 0)
{
engUnits = inTouchWrapper.Read(tagDotField.EngUnits);
}
else
{
engUnits = "N/A";
}
if (inTouchWrapper.Read(tagDotField.Description) != "")
{
description = inTouchWrapper.Read(tagDotField.Description);
}
else
{
description = "N/A";
}
descriptionlbl.Text = description;
englbl.Text = engUnits;
valuelbl.Text = value;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.Source);
MessageBox.Show(ex.HelpLink);
MessageBox.Show(ex.StackTrace);
}
}
private void WriteButton_Click(object sender, EventArgs e)
{
try
{
if (tagName == "")
{
MessageBox.Show("Please enter a tag!");
}
else
{
string inputValue = ValueBox.Text;
InTouchDdeWrapper inTouchWrapperWriter = new InTouchDdeWrapper();
inTouchWrapperWriter.Initialize();
TagDotField tagWriter = new TagDotField(inputValue);
inTouchWrapperWriter.Write(tagName, inputValue);
valuelbl.Text = inputValue;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
MessageBox.Show("Tag change successfull");
}
}
public int EngValidate(string engString)
{
string exception;
int x;
try
{
InTouchDdeWrapper inTouchWrapper = new InTouchDdeWrapper();
inTouchWrapper.Initialize();
TagDotField tagDotField = new TagDotField(tagName);
engString = inTouchWrapper.Read(tagDotField.EngUnits);
x = 1;
}
catch (Exception msg)
{
exception = msg.ToString();
if (exception == "")
x = 1;
else
x = 0;
}
return x;
}
}
}