-
The problem with your 'Cancel' button not
-
working with your input box, I suspect is
-
from this line here where you're assigning
-
a blank space to the strCancelClicked variable
-
You're assigning a blank space. What's
-
actually in the input box when you click
-
the 'Cancel' button is 'no character' or
-
what is what we call an empty string.
-
Now I've actually tested this and I want to
-
test it and show you how I tested it.
-
I test by setting a break point at
the 'Do Until' loop.
-
I'm going to run or debug your program
-
when the program code gets to this line
-
it will pause, we can actually look at
-
the values in each of these variables and
-
so what I'll do is run your program, I'll
-
enter two values for temperatures and then
-
for the third input I'll click the 'Cancel'
-
button. But after each value I input the
-
program is going to pause at this line
-
and allows us to look at the variables and
-
then we can continue on until the next
-
input and so on.
-
I'll start debugging. Enter the
temperature for month number 1.
-
Click the 'OK' button. The program code
-
pauses here. I can see the number of
-
entries is one. Of course the max entries
-
should be 12. The strTemp is 98, that's
-
what I entered and the strCanceled is
-
you can faintly see it there
'quote' 'space' 'quote'.
-
Again that's exactly what you assigned it.
-
Now I can continue the program code by
-
clicking the F5 or if we wanted to we
-
could go line by line by clicking the F8 key.
-
But we are just going to continue.
-
The program is going to prompt me for
-
month #2. Again we pause, the number of
-
entries is now 2, max number of entries
-
should stay at 12. What I entered into
-
the input box is 99 and again the
-
strCanceledClick is the 'space'.
-
One more continue. For the third
-
temperature I'm going to click the
-
'Cancel' button. Now the program again
-
pauses here, third entry, notice this
-
strTemp is 'quote' 'quote' but
-
strCanceled is 'quote' 'space' 'quote'.
-
That's why when we continue our program
-
you are prompted to enter a number of
-
months instead of it canceling. So what
-
I'm going to do is actually stop the
-
program, say 'Yes' you're not cancelling
-
out because of the blank space here. You
-
get rid of the blank space, I'm also going
-
to remove the break point. We're going
-
to run the program again. Now strCenceled
-
will equal the empty string. Again I'll
-
enter two temperatures, notice there's no
-
break point so it's not pausing the code.
-
For the third temperature I click 'Cancel'
-
and it breaks out of the loop, averages
-
the two temperatures, displays it,
-
the program is working fine.
-
I hope that you understand now the
-
difference between an empty string
and a blank space.