Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi!
Im a beginner at C# programming. Im studying a class in this language and unfortunatly im stuck:(


The assignment is about a Cinema system.
Userimputs a value-----> if valid it appears on the listbox with person name, ticket price and total revenue for the day.

the above i have no problem with!
The assignment needs me to have two classes. And in this second class
I need to convert the textbox price value into a double value.
so far no problem!

In this second class im requierd to implement a code that checks if the users
code fullfills the minlimit value which is 0 and that it is under the maxLimit
which i have put to a thousand. code looks like this:

C#
public static bool GetDouble(string StringToConvert, out double dblOutValue, double minlimit, double maxlimit= 100) {
 
    bool ConvertedDoubleNumber = Double.TryParse(StringToConvert, out dblOutValue);

    if (dblOutValue == maxlimit)
    {
        MessageBox.Show("Please enter a valid number ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
    }


I assumed that the users imput would get saved in dblOutValue but apperantly it does not get saved.

Kepp in mind that this is only a small code. I have a mainform since this is a forms application which has a bunch of code.

The only relevant thing to note here is that a code gets sent to the second class(utillityclass) and gets converted to a double value by suing tryparse.

I need that double value to issue a max/minlimit and for that i need help.
This requiers overloading and I tried that but the variable dblOutValue
does not exist in the other method since i cant use the same inparametes.
if i only use maxlimit and minlimit i cant get it to work.


Please help!
Regards
Peter!
Posted
Updated 9-Mar-12 12:13pm
v3

1 solution

Hi Peter,

your goal should be easy to achieve, but I think you mixed a few things.
Hope my code sample below is doing what you what you want to achieve.
It simply returns a Boolean "false" if "input"-value is < 1000.


C#
//Set Variables to save values after invoking GetDouble() In your MainForm
bool IsMaxLimit = false;
double out_value;
yes = GetDouble("646", out out_value, 100);
MessageBox.Show(IsMaxLimit.ToString() + " " + out_value);



C#
public static bool GetDouble(string StringToConvert, out double dblOutValue, double minlimit, double maxlimit = 1000)
        {
            //I didn't recognized where you want to check the conversation in your code
            //bool ConvertedDoubleNumber = Double.TryParse(StringToConvert, out dblOutValue);

            if (dblOutValue < maxlimit)
            {
                return false;
            }
            else
            {
                return true;
            }
        }



Hope it works for you.

Best Regards
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900