![]() ![]() | ||
In this chapter, we'll take a look at three crucial aspects of the Visual Basic language: procedures, scope, and exception handling. Dividing your code into procedures allows you to break it up into more modular units. As your programs become longer, that's invaluable as it stops everything from becoming too cluttered. In Visual Basic, all executable code must be in procedures. There are two types of procedures: Sub procedures and functions. In Visual Basic, Sub procedures do not return values when they terminate, but functions do.
As your code gets longer, it also becomes more important to know what parts of your code are accessible from other parts of your code; this issue is known as scope. Now that Visual Basic is laying a heavier emphasis on OOP, scope becomes a more important issue, as we'll see in this chapter and when we discuss OOP in detail in Chapter 11.
Finally, we'll take a look at exception handling in this chapter, because that's also something that's been given considerable emphasis in VB .NET. Exception handling is really runtime error handling in VB .NET (although other languages make a distinction between exceptions and errors). There are two ways to handle such exceptions: structured and unstructured exception handling. Structured exception handling uses the same Try…Catch…Finally type of construct that Java does; unstructured exception handling is really the traditional Visual Basic error handling that uses the On Error GoTo statement. We'll see both in this chapter.
![]() ![]() | ||