|
-
Apr 14th, 2007, 07:46 AM
#1
Thread Starter
Hyperactive Member
[2005] Any Help
Could any one help me with this error warning I am getting with my function.
Code:
Private Function GetShiftType() As String
Dim StartTime, EndTime As Date
Dim StartHour, EndHour As Double
StartTime = dtpStartTime.Text
EndTime = dtpEndTime.Text
StartHour = StartTime.TimeOfDay.TotalHours
EndHour = EndTime.TimeOfDay.TotalHours
If StartHour >= 7.0 AndAlso StartHour <= 8.5 AndAlso EndHour >= 12.0 AndAlso EndHour <= 16.0 Then
txtShiftType.Text = "Ealy"
btnUpdate.Focus()
ElseIf StartHour >= 12.0 AndAlso StartHour <= 15.0 AndAlso EndHour >= 19.0 AndAlso EndHour <= 21.0 Then
txtShiftType.Text = "Late"
btnUpdate.Focus()
ElseIf StartHour >= 7.0 AndAlso StartHour <= 8.5 AndAlso EndHour >= 19.0 AndAlso EndHour <= 21.0 Then
txtShiftType.Text = "Long Day"
btnUpdate.Focus()
ElseIf StartHour >= 19.0 AndAlso StartHour <= 21.0 AndAlso EndHour >= 7.0 AndAlso EndHour <= 9.0 Then
txtShiftType.Text = "Night"
btnUpdate.Focus()
ElseIf StartHour >= 15.0 AndAlso StartHour <= 18.0 AndAlso EndHour >= 0.0 Then
txtShiftType.Text = "Toalight"
btnUpdate.Focus()
Else
MessageBox.Show("The specified start and end times do not match any known shift.", "Check shift time")
dtpStartTime.Focus()
End If
End Function
Then end function is underline and the error message is as follows (Function 'GetShiftType' doesn't return a value on all code paths. A null reference exception could occur at run time when the result is used.)
Thanks
-
Apr 14th, 2007, 08:07 AM
#2
Hyperactive Member
Re: [2005] Any Help
you dont return a value to the GetShiftType that is why you get the warning.
use private sub instead of a private function.
or return a value using the function..
-
Apr 14th, 2007, 08:28 AM
#3
Re: [2005] Any Help
To reduce errors I would also consider using something like a numeric updown control, or even combo boxes instead of textboxes. That way the format would also be correct and you would vastly reduce the chances of errors.
I also dont see why you have the start and end time declared as Date when they would probably be best declared as Double.
-
Apr 14th, 2007, 08:38 AM
#4
Re: [2005] Any Help
You shouldn't be doing this:
vb Code:
Dim StartTime, EndTime As Date
'...
StartTime = dtpStartTime.Text
EndTime = dtpEndTime.Text
You should just be doing this:
vb Code:
Dim StartTime, EndTime As TimeSpan
'...
StartTime = dtpStartTime.Value.TimeOfDay
EndTime = dtpEndTime.Value.TimeOfDay
The DTP already contains Date values and you're converting them to Strings and back to Dates again. Never convert between a non-string type and the string type unless you need to.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|