Microsoft Office Tutorials and References
In Depth Information
What Causes Errors?
In your future development projects, you’ll encounter many external data storage
and management applications that mostly play well with Excel, but sometimes
might not when by all rights they should. It’s never in any reputable software
company’s best interests to impose nuisance bugs on its products’ users. The point is,
if you find that you have all your bases covered and are still scratching your head
about an error that has no rhyme or reason, you might have stumbled onto a bug
that other users of that product, and especially the software manufacturer, would
want to know about.
The process of debugging is a combination of art and science. The science is covered by some terrific
debugging tools that come with Excel VBA. The art is owing to the skills and experience you will
gain when you build VBA projects with a mindset for anticipating potential minefields based on the
intended use, and users, of your projects.
WHAT cAusEs Errors?
The world of computer programming enjoys no exemption from Murphy’s Law, where if something
can go wrong, it will go wrong. Three primary causes of errors can infect your VBA programming
code. To avoid errors, your first line of defense is anticipating problems as you write your code,
especially considering how the project will be used in real practice. Eventually, however, one of three
types of errors will impose their nuisance selves.
One cause is syntax errors , such as misspelling a VBA keyword, or not declaring a variable while
requiring variable declaration (as was outlined in Lesson 6). This causes a compile error as shown
in Figure 17-1, because the LastRow variable was not declared in that example. If an error can be
classified as friendly, it’d be a compile error because it is VBA’s way of telling you what’s wrong, and
sometimes showing you exactly where the problem is.
figurE 17-1
Search JabSto ::

Custom Search