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:
Dim KeepOn As Boolean Dim DateDefault As Date Dim strDate As String Dim Date1 As DateTime Dim MyDateFmt As String = "dd/MM/yyy HH:mm:ss" DateDefault = DateAdd("h", 21, Today()) ' Today 00 hours plus 21 hours KeepOn = True While KeepOn strDate = InputBox(" Enter date with format " + MyDateFmt, , _ Format(DateDefault, MyDateFmt)) Try Date1 = DateTime.Parse(strDate) KeepOn = False MsgBox(" No error detected in date.parse. Proceed" _ + Date1.ToString) Catch ex As Exception MessageBox.Show("Exception in Date.Parse" + _ vbNewLine + " Date string = " + strDate + _ vbNewLine + "Exception Type: " _ + ex.GetType.ToString + _ vbNewLine + "Exception Message: " _ + ex.Message, "Exception", _ MessageBoxButtons.OK, MessageBoxIcon.Error) KeepOn = True End Try End While




Reply With Quote