Results 1 to 7 of 7

Thread: InputBox

  1. #1

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Post

    How can I detect if the Cancel button has been clicked on my inputbox.

    I hate input boxes but there is a prerequisite on my course to use them!

    ------------------
    Matt G
    Either [email protected]] or [email protected]

  2. #2
    New Member
    Join Date
    Feb 2000
    Posts
    5

    Post

    there might be a better way than this but if they hit cancel the inputbox function will return "" (nothing).

    myStr = inputbox("enter name")

    if ( myStr = "" ) then
    ' they hit cancel
    end if

    but that only works if it isn't allowable to actually leave the field blank.

  3. #3

    Thread Starter
    Hyperactive Member gravyboy's Avatar
    Join Date
    Jan 2000
    Location
    Where I was before . . . if you don't know then you're new!
    Posts
    334

    Post

    That's how I initially did it. However I want to repeat the ionputbox if no reply is given ie FORCE the user to give an answer. I want to go down path x (repeat inputbox) if no answer is given and go down path y (clicked cancel - process accordingly) if cancel is clicked. :confused

    My existing code is

    Code:
    Ask_User:
       Ans=Inputbox("Answer is . . . ","Answer")
       If len(Ans)=0 or Ans="" then
          Goto Ask_User
       End If

    ------------------
    Matt G
    Either [email protected]] or [email protected]

  4. #4
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    I think the best you can do is this, because as far as I know you can't distinguish between the click of the cancel button and a null response.
    Code:
        Dim Ans As String
        Const DEFAULT = "Answer"
        
        Do Until (Trim(Ans) > "") And Ans <> DEFAULT
            Ans = InputBox("Answer is . . . ", "Please supply the Answer", DEFAULT)
            If Ans = "" Then
                MsgBox "You clicked Cancel or supplied a blank answer"
            End If
        Loop

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

    [This message has been edited by MartinLiss (edited 02-17-2000).]

  5. #5
    Hyperactive Member
    Join Date
    Nov 1999
    Posts
    363

    Post

    MSDN states "If the user clicks Cancel, the returns a zero-length string ("").", so Marty's right. However, you could provide " " as default. If they hit Enter without making any changes, you would have " " returned instead of "" that Cancel returns. Another option would be to make your own inputbox from a small form.

    Wade

  6. #6
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Email me if you'd like a form that looks like an InputBox that will do what you want, or look for a recent post by Aaron Young for the code for a subclassed InputBox.

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

  7. #7
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431

    Post

    Email me if you'd like a form that looks like an InputBox that will do what you want, or look for a recent post by Aaron Young for the code for a subclassed InputBox.

    ------------------
    Marty
    What did the fish say when it hit the concrete wall?
    > > > > > "Dam!"

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