Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8627611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T08:19:26+00:00 2026-06-12T08:19:26+00:00

I’m still a novice programmer(from C++) and I am creating a GIU which displays

  • 0

I’m still a novice programmer(from C++) and I am creating a GIU which displays a Tag from a running software. The purpose is to display the tag properties Description and Eng Units . I have been given 2 dlls InTouchDataAccess and NDde.
I’ve read on exception handeling and the best idea I’ve seen was this one:
Create a Validate function

which I did. But the program does no enter the function, I goes straigh into the catch block of my SelectButton_Click fct.

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;
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T08:19:27+00:00Added an answer on June 12, 2026 at 8:19 am

    You’re declaring a variable engString for your method which you don’t actually use. Additionally, the way you set this variable reads from the wrapper which can cause an exception (which is then catched by the outer catch block). A better approach would be to declare such a method reading only once:

    public bool TryRead(InTouchDdeWrapper wrapper, string prop, out string value) 
    {
      try 
      {
        value = wrapper.Read(prop);
        return true;
      }
      catch (Exception e)
      {
        value = null;
        return false;
      }  
    }
    

    Called like this:

    InTouchDdeWrapper wrapper = new InTouchDdeWrapper();
    wrapper.Initialize();
    
    TagDotField field = new TagDotField(tagName);
    
    string engUnits;
    
    if (!TryRead(wrapper, field.EngUnits, out engUnits)) 
    {
      engUnits = "N/A";
    }
    

    I hope you get the idea of this pattern. You instantiate (and initialize) a lot of classes over and over again in your code where it would be better to just have one wrapper, one field, etc … and to read the values only once. Additionally, you shouldn’t make use of return codes in C#, that’s what exceptions are for.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
In my XML file chapters tag has more chapter tag.i need to display chapters
I have a text area in my form which accepts all possible characters from
I am currently running into a problem where an element is coming back from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.