Fix Misteakes
Mistakes are a fact of life, and Visual Basic is fairly intolerant of them. If you followed along with the preceding lab, you probably already encountered that fact. Sometimes it’s pretty easy to tell what you’ve done wrong, and sometimes it’s almost impossible—even for experienced programmers! What marks the difference between beginning and expert programmers is how they go about solving those problems.
To help you understand fixing mistakes, you need to know that there are four different kinds of errors that are generally identified by where or why they happen:
- Syntax errors
Occur when you mistype a statement, such as omitting a closing parenthesis or omitting some part of the statement that is required. Visual Basic detects these errors right away and highlights them in red as soon as you move to the next line of code.
- Semantic errors
Are also often the result of a typo, but they appear valid to Visual Basic as you type. Examples of this kind of error include misspelling a method or property name or using a variable or procedure name that isn’t defined yet. Visual Basic checks for these errors the moment you run your code (for instance, when you press F5). At that point, Visual Basic converts your code into a form that Excel understands (this is called compiling), and if any of the names you used aren’t found, compiling stops and Visual Basic highlights the error. Semantic errors are sometimes called compile-time errors for that reason.
- Logic errors
Can ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access