This chapter introduces the core elements that make up Visual Basic 2008. Every software development
language has unique elements of syntax and behavior. Visual Basic 2008 has evolved
significantly since Visual Basic was introduced in 1991. Although Visual Basic has its origins in
traditional procedural-based programming languages, it began the transition toobjects back in 1995
with Visual Basic 4.0.
With the release of Visual Basic .NET (that is, Version 7), Visual Basic became a fully object-oriented
programming environment. Now with the release of Visual Basic 2008 (that is, Version 9), there
are still more new features, but at the core are the same basic types and commands that have been
with Visual Basic since its early stages. Objectparadigms extend the core elements of the language.
Therefore, while a very brief introduction to the existence of classes and objects within the language
is presented in this chapter, the key concepts of object-oriented development are presented in detail
in Chapters 2 and 3.
This chapter focuses on the core elements of the language, including questions about those language
elements a newdeveloper not familiar with Visual Basic might ask, such as where semicolons
should be placed. The key topics of this chapter include the following:
❑ Initial syntax and keywords to understand the basic language elements
❑ Value versus reference types
❑ Primitive types
❑ Commands: If Then Else, Select Case
❑ Value types (structures)
❑ Reference types (classes)
❑ Commands: For Each, For Next, DoWhile
Chapter 1: Visual Basic 2008 Core Elements
❑ Parameter passing ByVal and ByRef
❑ Variable scope
❑ Data type conversions, compiler options, and XML literals
The main goal of this chapter is to familiarize you with Visual Basic. The chapter begins by looking at
some of the keywords and language syntax you need. Experienced developers will probably gloss over
this information, asthis is just a basic introduction to working with Visual Basic. After this, the chapter
discusses primitive types and then introduces you to the key branching commands for Visual Basic. After
you are able to handle simple conditions, the chapter introduces value and reference types. The code
then looks at working with collections and introduces the primary looping control structure syntax forVisual Basic.
After this there is a brief discussion of boxing and value type conversions, conversions which often
implicitly occur when values are passed as parameters. Following these topics is a discussion of variable
scope, which defines the code that can see variables based on where they are defined in relationship to
that block of code. Finally, the chapter introduces basic data typeconversions, which includes looking
at the compiler options for Visual Studio 2008. Visual Studio 2008 includes a new compiler option and a
new data type, XML literals, which are also introduced in the context of conversions.
Initial Keywords and Syntax
While it would be possible to just add a giant glossary of keywords here, that isn’t the focus of this
chapter. Instead, a few basic elementsof Visual Basic need to be spelled out, so that as you read, you can
understand the examples. Chapter 7, for instance, covers working with namespaces, but some examples
and other code are introduced in this chapter.
Let’s begin with namespace. When .NET was being created, the developers realized that attempting
to organize all of these classes required a system. A namespace is an arbitrarysystem that the .NET
developers used to group classes containing common functionality. A namespace can have multiple
levels of grouping, each separated by a period (.). Thus, the System namespace is the basis for classes
that are used throughout .NET, while the Microsoft.VisualBasic namespace is used for classes in
the underlying .NET Framework but specific to Visual Basic. At its most basic...