Visual Basic .NET Program Errors


As you saw in this chapter, Visual Basic .NET requires you to play by certain rules when writing programs. Some rules concern the way in which you create names for variables . Other rules must be followed when creating program statements. Collectively, the rules that you must follow are called the syntax rules for Visual Basic .NET. You know that in this assignment statement:

 Age = 34 

the equal sign ( = ) is the assignment operator and that it requires two operands. When operands and operators are combined together correctly, they form an expression. One or more expressions form a program statement. By arranging program statements in a very specific way, you can create a program that you can run to solve a specific problem. You can see this relationship is Figure 4.8.

Figure 4.8. Progressing from operands and operators to a Visual Basic .NET program.

graphics/04fig08.gif

Semantic Errors

You can write a program that abides by the syntax rules but still doesn't work properly. You can do the same thing in English. For example, an English sentence usually has a noun and a verb. This sentence :

The dog meowed.

has a noun and a verb, and it abides by the syntax rules of English, but it doesn't make sense because dogs don't meow. This type of error is called a semantic error. In such errors, the syntax rules are followed properly, but the words (or operands, in the case of programming languages) are used out of context. You can write programs in Visual Basic .NET that have semantic errors. The bad news is that Visual Basic .NET may not be equipped to catch such errors.

You can also write programs that don't have either syntax or semantic errors but still produce incorrect results. Such errors are most often caused by problems with the design of the program, or its logic.

Any error in a program is called a bug, and the process of correcting and removing program errors is called debugging the program.

Note

graphics/note_icon.gif

The term was coined back in the early days of computers, when a moth flew into a computer and shorted out several wires. The engineers had to dismantle part of the computer to remove the body of the moth, hence the term debugging. Believe it or not, this little piece of trivia actually has come up at a cocktail party! This was also the answer to a million-dollar question on a popular game show. (The contestant answered it correctly.)


As you write programs throughout this book, I actually ask you to introduce bugs into them. I do this because it gives you some familiarity with how Visual Basic .NET handles program bugs. It also helps you become a better detective in isolating and correcting other bugs that might creep into your programs. Seeing Visual Basic .NET error messages under controlled circumstances is a valuable learning tool.



Visual Basic .NET. Primer Plus
Visual Basic .NET Primer Plus
ISBN: 0672324857
EAN: 2147483647
Year: 2003
Pages: 238
Authors: Jack Purdum

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net