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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:43:32+00:00 2026-06-07T22:43:32+00:00

I am having trouble getting a method working and I am not sure I

  • 0

I am having trouble getting a method working and I am not sure I am doing it the correct way. What I want to do is to send a string from a form by a button_click into a class and process it there for errors(tryparse method) and the send a boolvalue back to then either report and error to the user or to print input in an listbox.

This is the form code I have that is supposed to send the string into the class.

private void btnOK_Click(object sender, EventArgs e)
{
     Errorcheck.GetDouble(numChoice);
}

and then the Errorcheck class:

public static bool GetDouble(string numChoice, out double value, double minLimit, double maxLimit)
{
     while (!double.TryParse(numChoice, out value))
     {
          if ((value >= minLimit) && (value <= maxLimit))
          {
              return true;
          }
      }
      return false;
}

How do I retrieve the bool value from the Errorcheck class? if it was ok or not. Am I doing the right way or is there a quicker way to go about 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-07T22:43:34+00:00Added an answer on June 7, 2026 at 10:43 pm
    private void btnOK_Click(object sender, EventArgs e)
    {
       double foo;
       var myresult = Errorcheck.GetDouble(numChoice, out foo, 1, 2);
    
       //When myresult == true, foo contains the parsed value
    }
    

    myresult will contain the result returned by GetDouble either true (value could be parsed and is within limits) or false (value could be parsed but was out of limits or failed to parse in the first place). Also, foo will contain 0 if parsing failed, otherwise the parsed value (which, may or may not!) be within the limits.

    I do, however, have some problems with your code. First; why is your class named Errorcheck while, in fact, it doesn’t do error-checking (what is that anyway?) but parse a value.

    Second, why use the while() construct?

    public static bool GetDouble(string numChoice, out double value, double minLimit, double maxLimit)
    {
        return double.TryParse(numChoice, out value)
                 && ((value >= minLimit) && (value <= maxLimit));
    }
    

    Third; GetDouble() doesn’t actually “get” a “double”. It checks if a value is parseable as a double and, if so, is within bounds. It returns a bool for Pete’s sake.
    EDIT Scratch that; I missed the out on the method signature. It returns a bool and also the value.

    …and then some more but I might be nitpicking 😛

    And, last but not least, I don’t see what this has to do with “how bool values and variables get sent between classes/forms”?

    Take my, well intended, advice and get a good C# or general book on programming and brush up your basic skills a little. You will only benefit and soon you’ll see why your code is, no flame intended, “bad” in many ways.

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

Sidebar

Related Questions

im having trouble getting a string (containing a URL) from one activity to another.
I'm having trouble getting my form submission working. I'm using a preventDefault in order
I'm having trouble getting the onServiceConnected() method to run, which means that it's not
I'm having trouble getting the CanExecute method of my command to work property. I've
I am having trouble getting this invisibilityOfElementLocated() method to work. Here is the code
I'm having some trouble getting my head around the jquery queue method. I've got
I'm having trouble getting Tire working using ElasticSearch with the Bonsai addon on the
I'm having trouble figuring out why my web service is not working correctly when
I'm having trouble getting jquery.validation.js to validate a select box. It is working on
I'm having trouble getting the C# compiler to call an extension method I created,

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.