hello guys and girls, im new to this forum.. so please be gentle :)

Im developing this application to improve my ability to develop applications in c#.. so far i've fingured out that im not that good at it.

I fetched out my old college coursework case study to work on, and I have found an interesting one.. a ticket booking application for a ferry which writes data to text file (csv).

so far i have developed the UI. it has

  • tabControl with 4 tabs
  • 1st tab has 7 TextBox Controls, 1 Button Control, 2 dateTimePicker Controls
  • 2nd tab has a dataGrid Control and a Button

for time being, the 3rd and 4th tab are empty.

i have created a separate class file called functions.cs
it holds all my functions (like calculating fare, writing to file, reading to file)

the route of the ferry is fixed, so 2 of the textbox(s) are un editable and have a value by default.

I am new to dateTimePicker control. I should say its a marvellous time saving control!

1 of the date time picker (its called current date) is set to the current rundate (for eg: if today is 3rd April 2010, then the control shows 3rd April 2010.. and if you run the application on 12th Devember 2011, the control would show 12th december 2011 and so on.. i think you get my point here)

the problem i am facing is with the next datetimepicker control (which is called journey date).. my logic is incompatible (or i am incompetent) with min and max date properties of the control.

i need the 2nd datetimepicker control's min and max date to be a month ahead of current date..

in short , if the current date is today's date.. then the journey date must always be a month ahead of the current date. i.e. a user has to book for his/her tickets a month ahead of his/her journey.


another issue i am facing is with the text box. I have a weight limit on my booking. (its a ferry!) i should calculate the total weight of passenger and luggage and adjust the fare accordingly..

i already have my logic coded in my class file functions.cs..
the problem is with the UI..

3 textboxes are involved in this issue. passengerWeight, luggageWeight and theFare textboxes.

getFare() function gets text from passengerWeight and luggageWeight and returns a the fare based on the total weight.. the fare is of the type double.

I need to change the content so fthe textbox totalFare on the fly as soon as the user enters values in passengerWeight and luggageWeight..

if it was javascript, id have done this.. but i tried applying the same logic in c# but, i get this error

Input string was not in a correct format.

this is my code

private void luggageWeight_TextChanged(object sender, EventArgs e)
            double tpw = Convert.ToDouble(passengerWeight.Text);
            double tlw = Convert.ToDouble(luggageWeight.Text);
            double fare = getFare(tpw, tlw);
            thefare.Text = fare.ToString();

the call stack showed me only the first character i entered in the textbox..

so here i am!, clueless what to do... how do i fix this error and solve the dateTimePicker control problem?

any help will be greatly appreciated :)

Hi emclomdon,

For your "Input string was not in a correct format" error, consider using double.TryParse(...) , which will allow you to catch null/invalid values and assign them accordingly as zero. Also consider assigning default values and filtering the input if you have not already.

For your DateTimePicker, the MinDate and MaxDate properties are supposed to limit the min and max selectable dates, so I am unsure why you are not getting the desired result. Look at this usage example and see if you can spot your problem: http://msdn.microsoft.com/en-us/library/system.windows.forms.datetimepicker.mindate.aspx

I'd recommend you look to change the datetimepickers min and max values in your forms Load event. You can't implement your logic in the designer, but you once the form loads you can get todays date and set the values as appropriate. Have a look at DateTime.AddMonths too.

Hi guys, thanks for your suggestions. Unfortunately, none of them worked out for me.

class myclass
 myfunctions mfo = new myfunctions();
private void passengerWeight_TextChanged(object sender, EventArgs e)
                double pw = Convert.ToDouble(passengerWeight.Text);
                double lw = Convert.ToDouble(luggageWeight.Text);
                double tw = pw + lw;
                double fare = mfo.getFare(tw);
                fareBox.Text = Convert.ToDouble(fare);
            catch(Exception myw)

I have also tried using


I still get the same error.. which is "Input String was not in a correct format".. and about the Double.TryParse(string); im unsure of how to use it as i have never used it. so its kinda new to me.


and about the dateTimePicker control. Im afraidi must have not interpreted the proper logic myself. i will read the case study and will try to solve it myself ..

appreciate the help guys :)

thanks a lot!

Is it failing when you have typed in a value or are some of the fields empty?
double.TryParse works like this:

double num; //store result
bool success; //store boolean value returned by tryparse

success = double.TryParse(txtNumber.Text, out num) //out keyword creates reference to output variable

    //input was correctly formatted
    //num now stores the parsed value
    //input not correctly formatted
    //num = 0

What was it about the datatimepicker you werent sure about?

I want some information about on-the-fly programing in C#,I want it for my project,
please help me as soon as possible!!!!