Datasheet
8
❘
CHAPTER 1 VISUAL STUDIO 2010
Even though the focus of this chapter is on Visual Studio, during this introduction a few basic elements of
Visual Basic will be referenced and need to be spelled out. This way as you read, you can understand the
examples. Chapter 4, for instance, covers working with namespaces, but some examples and other code
are introduced in this chapter that will mention the term, so it is defi ned here.
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 arbitrary system 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 specifi c to Visual Basic. At its most basic level, a namespace does not imply or indicate
anything regarding the relationships between the class implementations in that namespace; it is just a
way of managing the complexity of both your custom application ’ s classes, whether it be a small or large
collection, and that of the .NET Framework’s thousands of classes. As noted earlier, namespaces are covered
in detail in Chapter 4.
Next is the keyword
Class . Chapters 2 and 3 provide details on object - oriented syntax and the related
keywords for objects and types, but a basic defi nition of this keyword is needed here. The Class keyword
designates a common set of data and behavior within your application. The class is the defi nition of an
object, in the same way that your source code, when compiled, is the defi nition of an application. When
someone runs your code, it is considered to be an instance of your application. Similarly, when your code
creates or instantiates an object from your class defi nition, it is considered to be an instance of that class,
or an instance of that object.
Creating an instance of an object has two parts. The fi rst part is the
New command, which tells the
compiler to create an instance of that class. This command instructs code to call your object defi nition
and instantiate it. In some cases you might need to run a method and get a return value, but in most cases
you use the New command to assign that instance of an object to a variable. A variable is quite literally
something which can hold a reference to that class ’ s instance.
To declare a variable in Visual Basic, you use the
Dim statement. Dim is short for “ dimension ” and comes
from the ancient past of Basic, which preceded Visual Basic as a language. The idea is that you are telling
the system to allocate or dimension a section of memory to hold data. As discussed in subsequent chapters
on objects, the Dim statement may be replaced by another keyword such as Public or Private that not only
dimensions the new value, but also limits the accessibility of that value. Each variable declaration uses a Dim
statement similar to the example that follows, which declares a new variable, winForm :
Dim winForm As System.Windows.Forms.Form = New System.Windows.Forms.Form()
In the preceding example, the code declares a new variable ( winForm ) of the type Form . This variable is
then set to an instance of a Form object. It might also be assigned to an existing instance of a Form object
or alternatively to Nothing . The Nothing keyword is a way of telling the system that the variable does not
currently have any value, and as such is not actually using any memory on the heap. Later in this chapter, in
the discussion of value and reference types, keep in mind that only reference types can be set to Nothing .
K EYWO RD DES CRI PT ION
Nothing Used to indicate that a variable has no value. Equivalent to null in other languages and
databases.
Me A reference to the instance of the object within which a method is executing
Console A type of application that relies on a command - line interface. Console applications are
commonly used for simple test frames. Also refers to a .NET Framework Class that manages
access of the command window to and from which applications can read and write text data.
Module A code block that isn ’ t a class but which can contain Sub and Function methods. Used
when only a single copy of code or data is needed in memory.
TABLE 1-2
(continued)
CH001.indd 8CH001.indd 8 4/5/10 11:56:13 AM4/5/10 11:56:13 AM