Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
Greetings !
I have an InputBox. How do I distinguish between a valid input value of 2 and the user clicking on the "Cancel" button ? This worked just FINE - until I entered a value of 2 ! Ans = InputBox( _ "Enter a value between 1 and 5, myTitle, TP) If Ans = vbCancel Then Exit Sub TP = Ans |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
When I hit Cancel (or X) on an InputBox, I get the returned value of 0
(Zero). If Ans = 0 Then Exit Sub Tested using Excel 97SR2 on Windows 98SE, HTH Paul -------------------------------------------------------------------------------------------------------------- Be advised to back up your WorkBook before attempting to make changes. -------------------------------------------------------------------------------------------------------------- Greetings ! I have an InputBox. How do I distinguish between a valid input value of 2 and the user clicking on the "Cancel" button ? This worked just FINE - until I entered a value of 2 ! Ans = InputBox( _ "Enter a value between 1 and 5, myTitle, TP) If Ans = vbCancel Then Exit Sub TP = Ans |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
According to help:
If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (""). you must have Ans dim'd as a number. -- Regards, Tom Ogilvy wrote in message ... When I hit Cancel (or X) on an InputBox, I get the returned value of 0 (Zero). If Ans = 0 Then Exit Sub Tested using Excel 97SR2 on Windows 98SE, HTH Paul -------------------------------------------------------------------------- ------------------------------------ Be advised to back up your WorkBook before attempting to make changes. -------------------------------------------------------------------------- ------------------------------------ Greetings ! I have an InputBox. How do I distinguish between a valid input value of 2 and the user clicking on the "Cancel" button ? This worked just FINE - until I entered a value of 2 ! Ans = InputBox( _ "Enter a value between 1 and 5, myTitle, TP) If Ans = vbCancel Then Exit Sub TP = Ans |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
Maybe, I'm missing something. I thought that he was trying to return a
number between 1 and 5. Paul ------------------------------------------------------------------------------------------------------ According to help: If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (""). you must have Ans dim'd as a number. |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
But he was making his comparison to vbCancel which is a two and is usable
with a msgbox, not an input box. ? vbCancel 2 You said hitting cancel in an inputbox returns zero - it doesn't "When I hit Cancel (or X) on an InputBox, I get the returned value of 0 (Zero)." Tested in the immediate window (cancel was selected) ? inputbox("abc") ------ it returned a null string ? typename(inputbox("abc")) String A vba inputbox always returns a string. An empty string is coerced to zero in most cases if you force it to be used as a number, but not always. For instance ? inputbox("abc") = 0 raises a type mismatch error when I hit cancel. I just provided information on what an inputbox actually returns. -- Regards, Tom Ogilvy wrote in message ... Maybe, I'm missing something. I thought that he was trying to return a number between 1 and 5. Paul -------------------------------------------------------------------------- ---------------------------- According to help: If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (""). you must have Ans dim'd as a number. |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
Probably, but an inputbox will return a string. Text. "1", "5", or similar. If Ans is
declared as a String then the thing is not a number. If it's Long or Double then VBA may convert it by helpful intelligence -but it will crash merciless if you enter "Dont know" into the box. Anyway, Cancel returns "" no matter what you prompt for desired entries. -- HTH. Best wishes Harald Followup to newsgroup only please. wrote in message ... Maybe, I'm missing something. I thought that he was trying to return a number between 1 and 5. Paul ---------------------------------------------------------------------------------------- -------------- According to help: If the user clicks OK or presses ENTER , the InputBox function returns whatever is in the text box. If the user clicks Cancel, the function returns a zero-length string (""). you must have Ans dim'd as a number. |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
vbCancel
You're right.
I was using the InputBox method (Application.InputBox) rather than the InputBox function. I should have read the OP's question and your response in a less cursory manner. Paul ----------------------------------------------------------------------- On Thu, 23 Oct 2003 15:09:17 -0400, "Tom Ogilvy" wrote: But he was making his comparison to vbCancel which is a two and is usable with a msgbox, not an input box. ? vbCancel 2 You said hitting cancel in an inputbox returns zero - it doesn't "When I hit Cancel (or X) on an InputBox, I get the returned value of 0 (Zero)." Tested in the immediate window (cancel was selected) ? inputbox("abc") ------ it returned a null string ? typename(inputbox("abc")) String A vba inputbox always returns a string. An empty string is coerced to zero in most cases if you force it to be used as a number, but not always. For instance ? inputbox("abc") = 0 raises a type mismatch error when I hit cancel. I just provided information on what an inputbox actually returns. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
EXIT SUB UPON VBCANCEL | Excel Discussion (Misc queries) |