Using Visual Basic .NET with Web Matrix


You ve got an engine and components (ASP.NET) and a tool for putting them together (Web Matrix). Now you can program all these elements so that your pages perform the tasks you want them to perform. So what language do you use for this programming?

As it turns out, ASP.NET supports many different programming languages. You could program your Web pages in any of 16 (and counting) different languages, including Visual Basic .NET, C#, C, C++, Perl, and many others.

Web Matrix supports building ASP.NET Web applications using either Visual Basic .NET or C#. In this book, we re going to use Visual Basic .NET. I ve chosen Visual Basic .NET for a couple of reasons. The first is that if you ve programmed before, it s more likely that you ve worked with Visual Basic (or at least a Basic-like language) than with any other language. A second reason is that Visual Basic. NET, like all Basic languages, is a little more forgiving than some of its peers. For example, Visual Basic .NET isn t case sensitive, whereas many other languages (such as C and C++) are you can write Fill or fill or fILL and it s all the same to Visual Basic .NET. It s also a little more verbose than a language such as C or C#. For these reasons, I feel that Visual Basic .NET is the best language to use with Web Matrix. Your learning curve will be lower, and we can concentrate more on Web programming than on Web programming.

start sidebar
Why not C#?

Those of you who might have worked with C-type languages before might take exception to my choice of Visual Basic .NET on many grounds. To those who prefer C-type languages, I encourage you to work with C#, a language introduced with the .NET Framework. I won t show C# versions of the code in this book, but you can use C# to write every application we create in Visual Basic .NET with equivalent performance.

end sidebar

It would be impractical for me to turn this book into a book on Visual Basic .NET specifically because we want to focus on applying Visual Basic .NET to Web programming. The good news is that the Visual Basic .NET portion of the Web pages you ll be creating isn t that complex. True, there will be times when you have to perform some convoluted tasks with controls (and with data, especially), but that isn t a function of Visual Basic .NET it s an inherent part of working with ASP.NET, and trust me, I ll be explaining those bits in some detail.

If you re new to Visual Basic like languages, you might find the following lightning primer useful. Here I review all the basic concepts and structures that come up all the time in Visual Basic programming. The way you ll really learn all the basics, of course, is to actually use them. I ll show you the programs as we go along and explain what they do. Between the following introduction and the sample code you ll find throughout the book, you should have little trouble getting underway quickly.

start sidebar
Coding Style

All programmers have their own coding style, and there are many schools of thought on the best way to program. This book is a teaching book, so I m using a coding style designed to emphasize clarity over efficiency (which I put in quotation marks because even that term is subject to interpretation). Some programmers might disagree with the coding style I use, suggesting that it s simplistic or that the style might be unsuitable for professional programming. These are certainly valid opinions. However, I believe that the style I use for examples in this book makes the examples clear and comprehensible for new Web programmers while keeping the examples as short as possible. (Most of the programs you ll write in this book are less than 20 lines long.) If you are interested in developing your Visual Basic .NET skills further, I recommend two excellent books: Microsoft Visual Basic .NET Step by Step by Michael Halvorson (Microsoft Press, 2002) and OOP with Microsoft Visual Basic .NET and Microsoft Visual C# .NET Step by Step by Robin A. Reynolds-Haertle (Microsoft Press, 2002). The coding style I m using follows these rules:

  • Perform one task per line. As much as possible, I try to limit the code to carry out one task in a single line set one property or call one method. Sometimes this style isn t practical, but it s a worthy guideline to follow when writing Web Matrix programs.

  • Name controls according to their type. If I use a TextBox control for a phone number, I call it textPhone. The issue of naming is a near-religious issue among programmers some programmers like specifying the type for controls, while others think using the type in the name causes problems if you change types later. I find that including the type with the name of a control helps me remember the names better and reduces errors. In the end, the issue isn t what particular style you choose; the most important naming convention is simply consistency.

  • Avoid deeply nested code. It s hard to keep track when you have several layers of If-Then conditions, so I try to find ways to avoid nesting the code too deeply.

  • When possible, let Visual Basic .NET convert data types for you, such as converting from an integer to a string. That is, take advantage of implicit data coercion.

Now that I ve stated these guidelines, I invite you to use whatever coding style you re comfortable with. If you don t like the way I name variables, for example, you re quite welcome to use whatever style works for you!

end sidebar



Microsoft ASP. NET Web Matrix Starter Kit
Microsoft ASP.NET Web Matrix Starter Kit (Bpg-Other)
ISBN: 0735618569
EAN: 2147483647
Year: 2003
Pages: 169
Authors: Mike Pope
BUY ON AMAZON

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