Results 1 to 4 of 4

Thread: [RESOLVED] [2005] Pressing Cancel on InputBox

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    Resolved [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

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2006
    Posts
    910

    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!

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

  4. #4
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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
  •  



Click Here to Expand Forum to Full Width