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 8314515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:50:42+00:00 2026-06-08T20:50:42+00:00

I have a subroutine. It comapares whether values are empty then doing something. For

  • 0

I have a subroutine. It comapares whether values are empty then doing something. For example, if they are empty, then warnings are raised.
The code works fine. But when value are not empty, the warnings are still pop out. Please help me to correct the logic.

Thanks.

private void btnNew_Click(object sender, EventArgs e)
    {
        try
        {
            if (txtbox1.Text.ToString().Trim() == string.Empty)
            {
                goto Msg1;
            }
            if (txtbox2.Text.ToString().Trim() == string.Empty)
            {
                goto Msg2;
            }
            DataRow dr = mydataSet.Tables[0].NewRow();
            dr["Descript"] = txtbox1.Text;
            dr["Abbr"] = txtbox2.Text;
            dr["SortOrder"] = Convert.ToDecimal(numericOrder.Value);
            if (SortOrders.Contains((decimal)dr["SortOrder"]))
            {
                goto Msg3;
            }
            mydataSet.Tables[0].Rows.Add(dr);
            dgv.DataSource = mydataSet.Tables[0];
        Msg1:
            MessageBox.Show("Description is required.");
        Msg2:
            MessageBox.Show("Abbr is required.");
        Msg3:
            MessageBox.Show("Please select another one, this one is already used.");
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

From the above code, you see. if txtbox1 has some value, the program still displays Msg1. I want to avoid it.

  • 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-08T20:50:44+00:00Added an answer on June 8, 2026 at 8:50 pm

    Because labels are just labels, and code after them is executed sequentially.

    Why can’t you do just this:

        try
        {
            if (txtbox1.Text.ToString().Trim() == string.Empty)
            {
                MessageBox.Show("Description is required.");
                return;
            }
            if (txtbox2.Text.ToString().Trim() == string.Empty)
            {
                MessageBox.Show("Abbr is required.");
                return;
            }
            DataRow dr = mydataSet.Tables[0].NewRow();
            dr["Descript"] = txtbox1.Text;
            dr["Abbr"] = txtbox2.Text;
            dr["SortOrder"] = Convert.ToDecimal(numericOrder.Value);
            if (SortOrders.Contains((decimal)dr["SortOrder"]))
            {
                MessageBox.Show("Please select another one, this one is already used.");
                return;
            }
            mydataSet.Tables[0].Rows.Add(dr);
            dgv.DataSource = mydataSet.Tables[0];
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    

    It’s so much more readable.

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

Sidebar

Related Questions

I have a subroutine to insert a record to sql server table. The code:
hi folks i have a subroutine called CheckDate() in the code behind. How would
I have code that calls an ENTRY in a SUBROUTINE before the SUBROUTINE .
I have a subroutine called debug I use in my code. It basically allows
I have a Fortran numerical code that calls a subroutine from an external module.
Say I have the below code: program test call foo call foo contains subroutine
Let's say I have a subroutine/method that a user can call to test some
I have a Perl subroutine which returns an array of vaules, and I'd like
I have a subroutine that changes its operation slightly to include either one list
Suppose we have a subroutine returning a reference sub aspirin { my @items =

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.