userName
,
then
YourName
will work perfectly fine ask ing for a name and storing it in
userName
, but once
YourName
is fin ished,
userName
is forgotten.
If you have for gotten to declare a vari able, like
userName
, you might have
a perfectly good
YourName
pro cedure and a perfectly good
DoingWell
pro ce-
dure, but when
DoingWell
is run, it says “Good job,” not “Good job, Ada.” If
your pre sentation seems to be forgetful, check your
Dim
state ments to be sure
that you have de clared all your variables at the beginning of the module.
Final Word on Debugging and Er ror Prevention
The final word on de bugging and error prevention is to test what you have
done. If you can, test each pro cedure and/or but ton right away, so you can fix
any prob lems be fore you have too much code with too many problems to deal
with. But most im portant, test. You can’t fix a bug that you don’t find. And be-
lieve me, your stu dents will find the bugs. Try clicking on but tons that you did n’t
want the students to click on, clicking on wrong answers, and typ ing un expected
things. Your students will, and your presentation needs to be prepared for that.
Debugging and error prevention is more of an art form than a science. You
will de velop your own techniques the more comfortable you get. But de bugging
and error prevention is very important because you will have bugs (fewer if you
use the error prevention techniques), and you will need to correct them.
Con clu sion
In this chap ter you learned about ways to find bugs, how to fix bugs, and
how to prevent bugs. Now that you have learned a great many VBA tricks and
how to make your code work (or fix it when it doesn’t), you are ready to create
your own pro jects as well as create templates for your stu dents’ pro jects. The
next chapter talks about the idea of creating templates that pro vide the frame-
work of a pro ject for your stu dents so they can fill in the content.
170 De bug ging Tips
Do'stlaringiz bilan baham: |