Help regarding conversion error facing in the code

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi,
I am facing a conversion error in my code. Regarding the code explanation, i have two text box one with start date and end date. the end date needs to be populated automatically based on the start date value.i have a combo box with three levels namely Low, Medium and High. When I select Low in the combo box, the start date textbox will be populated with current date and time (format: 27-01-2013 17:56:02) and the duedate will be filled with 6 hrs from the start date. like same when i select medium 8 hrs will be added to the startdate and when i select High 14 hrs needs to be added with time.
My working hours starts from 09:00:00 and ends by 18:00:00 in the evening
If the enddate falls after my working time, then the off work time needs to be neglected.
say for example the level is medium and my startdate is 27/01/2013 16:58:18 then my enddate will be calculated as 28/01/2013 12:58:18. ie 8 hrs will get added from the start date.
below is the code for the sub procedure i am using. Public Sub AddHrs()
If frmInProgress.txtComplexity.Text = "Low" Then
frmInProgress.txtDueDate.Text = Format(due6Hrs(frmInProgress.txtStartdate.Text), "dd-MM-yyyy HH:mm:ss")
ElseIf frmInProgress.txtComplexity.Text = "Medium" Then
frmInProgress.txtDueDate.Text = FormatDateTime(due8Hrs(frmInProgress.txtStartdate.Text), "dd-MM-yyyy HH:mm:ss")
ElseIf frmInProgress.txtComplexity.Text = "High" Then
frmInProgress.txtDueDate.Text = Format(due14Hrs(frmInProgress.txtStartdate.Text), "dd-MM-yyyy HH:mm:ss")
End If
End Sub
Private Function due6Hrs(ByVal st As DateTime) As DateTime
If st.Hour < 13 Then
Return st.AddHours(6)
Else
Return st.AddHours(21)
End If
End Function
Private Function due8Hrs(ByVal st As DateTime) As DateTime
If st.Hour < 10 Then
Return st.AddHours(8)
Else
Return st.AddHours(23)
End If
End Function
Private Function due14Hrs(ByVal st As DateTime) As DateTime
If st.Hour > 9 Then
Return st.AddHours(28)
End If
Return st.AddHours(28)
End Function
the above error is throwing conversion error stating "Conversion from string "27-01-2013 18:20:48" to type Date is not valid." on the codefrmInProgress.txtDueDate.Text = FormatDateTime(due8Hrs(frmInProgress.txtStartdate.Text), "dd-MM-yyyy HH:mm:ss")
Can anyone please help me to over come this error?
Thanks in advance for your kindly help.
Regards,
Karthik Venkatraman
Thanks you and Kind Regards, Karthik Venkatraman

View the full article
 
Back
Top