|
-
Sep 21st, 2007, 11:06 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] [2005] Pressing Cancel on InputBox
Has anyone came up with a solution on how to catch a blank entry or the cancel button being pressed. I have found a few posts on it but not resolution. Here's what I have. DateUp is of Date type. It errors out saying "" cannot be converted to date if I press cancel or leave it blank. Any ideas?
Code:
DateUp = InputBox("Please enter the date", "Date Needed")
If DateUp = "" Then
Exit Sub
End If
-
Sep 21st, 2007, 11:08 AM
#2
Re: [2005] Pressing Cancel on InputBox
Dont use InputBox, create your own custom form designed like an InputBox, and place a DateTimePicker control on it instead of a TextBox, call it with ShowDialog.
-
Sep 21st, 2007, 11:15 AM
#3
Thread Starter
Fanatic Member
Re: [2005] Pressing Cancel on InputBox
Not a bad idea at all Atheist, I never thought of that. I may have to try that. I also found another way to make it not error out. I just used a try catch block and it works well too. Thanks for the input!
 Originally Posted by Atheist
Dont use InputBox, create your own custom form designed like an InputBox, and place a DateTimePicker control on it instead of a TextBox, call it with ShowDialog.
-
Sep 21st, 2007, 11:48 AM
#4
Re: [RESOLVED] [2005] Pressing Cancel on InputBox
You shouldn't use a Try Catch block to control your program flow. If you know that a blank value screws you up, code for that. You can take the input from the InputBox into a string and then use the DateTime.TryParse method to see if it is a valid date. If you do this, it will handle the blank scenario, but it will also handle the scenario if someone types in "AAAA".
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
|