27-11-2012, 05:39 PM
Understanding Visual Basic.NET Syntax and Structure
Understanding Visual.pdf (Size: 297.35 KB / Downloads: 21)
All the examples in this book are written in Visual Basic.NET. Why, you ask, have we decided
to use Visual Basic exclusively since the .NET platform supports a plethora of languages?
Why not pepper the text with examples in C#, Jscript, and maybe even Eiffel? We decided to
concentrate our efforts on only one language to simplify things and to keep the book to a reasonable
length. While it’s certainly nice to be able to develop ASP.NET applications using a
number of different languages, let’s face it: Most programmers prefer to program in a single
language. But why have we decided to use Visual Basic? After all, isn’t C# now Microsoft’s
preferred language? Quite the contrary: Visual Basic is now on equal footing to C++ and the
new C#. In addition to this fact, we have chosen to use Visual Basic.NET in this book for several
reasons. Visual Basic is the most popular programming language in the world. It’s also by
the far the most common language that existing ASP developers have used to create “classic”
ASP pages. Finally, it’s the language that the authors of this book cut our teeth on—the
language that we personally prefer to use.
More than likely, you fall into one of three categories of Visual Basic (VB) developers:
1. You have little or no experience developing applications with Visual Basic or the
VBScript scripting language.
2. You have considerable experience developing ASP applications using VBScript but little
or no experience with VB proper.
3. You have considerable experience using the Visual Basic language (and perhaps
VBScript as well).
The New Look of Visual Basic
To borrow the catch phrase of a now defunct U.S. car manufacturer, “This is not your father’s
Visual Basic!” While true to its heritage, Visual Basic.NET is a much-improved version of the
venerable Visual Basic language that many of us have grown to love. Visual Basic has matured
into a full-featured, object-oriented language. But unlike previous releases of Visual Basic, this
version of VB was rebuilt from the ground up. Literally.
In moving to VB.NET, Microsoft has ditched a number of older, arcane features like GoSub
and default properties, and totally reworked features such as arrays and data types. Other
native features like the MsgBox function and the Cxxx convert functions have been demoted.
These demoted features are still in VB.NET but Microsoft is recommending that you move to
using the .NET System classes instead. Of course, depending on your experience and base of
existing legacy VB applications, some of the changes may cause considerable pain. More than
likely, however, you will soon grow to appreciate the redesigned VB language.
Functions
Functions in VB.NET are similar in functionality to subroutines with one difference: Functions
can return a value to the calling program. You create a function with the Function statement.
For example, the following function returns “Hello World” to the calling code:
Implicit and Explicit Variable Declarations
VB has always supported implicit variable declarations, which means that you are not required
to declare your variables or parameters before using them. However, most professional developers
agree that you should not take advantage of this VB feature unless you like bugs in your
code. The issue is best demonstrated with an example: