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]
Printable View
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]
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.
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]
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).]
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
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!"
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!"