Results 1 to 2 of 2

Thread: code to input date-time using InputBox

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Location
    Melbourne
    Posts
    37

    code to input date-time using InputBox

    Here is my code to input date-time using InputBox
    with default date-time = today at 9 pm
    I thought others might be interested or suggest improvements
    vb.net Code:
    1. Dim KeepOn As Boolean
    2.         Dim DateDefault As Date
    3.         Dim strDate As String
    4.         Dim Date1 As DateTime
    5.         Dim MyDateFmt As String = "dd/MM/yyy HH:mm:ss"
    6.  
    7.         DateDefault = DateAdd("h", 21, Today())
    8.        ' Today 00 hours plus 21 hours
    9.         KeepOn = True
    10.  
    11.         While KeepOn
    12.             strDate = InputBox(" Enter date with format " + MyDateFmt, , _
    13.                                Format(DateDefault, MyDateFmt))
    14.  
    15.             Try
    16.                 Date1 = DateTime.Parse(strDate)
    17.                 KeepOn = False
    18.                 MsgBox(" No error detected in date.parse.  Proceed"  _
    19.                            + Date1.ToString)
    20.                    
    21.             Catch ex As Exception
    22.                 MessageBox.Show("Exception in Date.Parse" + _
    23.                            vbNewLine + " Date string = " + strDate + _
    24.                            vbNewLine + "Exception Type: " _
    25.                             + ex.GetType.ToString + _
    26.                            vbNewLine + "Exception Message: "  _
    27.                            + ex.Message, "Exception", _
    28.                            MessageBoxButtons.OK, MessageBoxIcon.Error)
    29.                 KeepOn = True
    30.             End Try
    31.  
    32.         End While
    Last edited by Hack; Dec 15th, 2011 at 08:26 AM. Reason: Added Highlight Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width