1 Replies - 367 Views - Last Post: 27 January 2013 - 06:15 AM Rate Topic: -----

#1 karthik82.vk  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 01-November 12

Help regarding conversion error facing in the code

Posted 27 January 2013 - 05:55 AM

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 code is throwing conversion error stating "Conversion from string "27-01-2013 18:20:48" to type 'Date' is not valid." on the code

frmInProgress.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

Is This A Good Question/Topic? 0
  • +

Replies To: Help regarding conversion error facing in the code

#2 andrewsw  Icon User is offline

  • It's just been revoked!
  • member icon

Reputation: 3609
  • View blog
  • Posts: 12,417
  • Joined: 12-December 12

Re: Help regarding conversion error facing in the code

Posted 27 January 2013 - 06:15 AM

Private Function due8Hrs(ByVal st As DateTime) As DateTime


This function is expecting a DateTime value but you are passing it text (frmInProgress.txtStartdate.Text).

The first thing I would do would be to convert the text in the textbox to a DateTime value:

Dim dtBegin As DateTime = DateTime.Parse("27/01/2013 16:58:18")


Of course, using a DateTimePicker would be easier.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1