10 Replies - 441 Views - Last Post: 05 December 2011 - 06:55 AM Rate Topic: -----

#1 riceformvp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-December 11

How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 08:19 PM

public decimal Fee(int InHour, int OutHour, int InMinute, int OutMinute)
        {
            TimeSpan span1 = TimeSpan.FromHours(InHour);
            TimeSpan span2 = TimeSpan.FromHours(OutHour);
            TimeSpan span3 = TimeSpan.FromMinutes(InMinute);
            TimeSpan span4 = TimeSpan.FromMinutes(OutMinute);
            TimeSpan span5 = span2.Subtract(span1) + span4.Subtract(span3);
            
            lblTotal.Text = (span5.TotalHours * 3).ToString("$#0.00");

            if (dtmOut.Value < dtmIn.Value)
                lblTotal.Text = "";
            if (dtmOut.Value < dtmIn.Value) 
                MessageBox.Show("No Overnight working/Clock out time is less than Clock in time.");
            
            
            
            

            



            

        }

        private void btnCalculate_Click(object sender, EventArgs e)

        {
            int InHour = dtmIn.Value.Hour;
            int InMin = dtmIn.Value.Minute;
            int OutHour = dtmOut.Value.Hour;
            int OutMin = dtmOut.Value.Minute;
            lblFee.Text = String.Format("{0:C}", Fee(InHour, InMin, OutHour, OutMin));
            


        }
        }
    
}


This post has been edited by Atli: 04 December 2011 - 09:55 PM
Reason for edit:: Fixed the [code] tags.


Is This A Good Question/Topic? 0
  • +

Replies To: How do I fix this error? "Not all Code paths return a value"?

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 08:33 PM

Does the function return a value? for every possible path?
Was This Post Helpful? 0
  • +
  • -

#3 riceformvp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-December 11

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 08:35 PM

I believe so. The error underlines "Fee".
Was This Post Helpful? 0
  • +
  • -

#4 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 08:49 PM

Obviously you're incorrect. As I can't see a single return statement anywhere.
Was This Post Helpful? 0
  • +
  • -

#5 riceformvp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-December 11

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 08:55 PM

Where would be the appropriate place to put "return"?
Was This Post Helpful? 0
  • +
  • -

#6 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 09:06 PM

Where do think it should go?
Was This Post Helpful? 0
  • +
  • -

#7 riceformvp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-December 11

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 09:30 PM

Towards the end. The only problem is, when I put a "return" statement, it then tells me I need to convert to decimal.
Was This Post Helpful? 0
  • +
  • -

#8 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 09:41 PM

Then post the Fee function code as you have written it with the return.

And use the code tags correctly, see entry in my signature.
Was This Post Helpful? 0
  • +
  • -

#9 riceformvp  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 04-December 11

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 09:59 PM

I use a return, but the same error reoccurs.
Was This Post Helpful? 0
  • +
  • -

#10 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2216
  • View blog
  • Posts: 9,351
  • Joined: 29-May 08

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 04 December 2011 - 10:12 PM

Show us the damn code you're using.
Was This Post Helpful? 0
  • +
  • -

#11 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: How do I fix this error? "Not all Code paths return a value"?

Posted 05 December 2011 - 06:55 AM

Could you format your code a little nicer please... :) ?
And put all of your code...

Anyways if you say the method will return a decimal
public decimal Fee(int InHour, int OutHour, int InMinute, int OutMinute)


Then it MUST return decimal, no other type. So if you're working with some other type convert it into decimal then use the return statement.

Here's some info on the return statement MSDN
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1