The .NET Framework
Something that I quickly realized was just how right those old hands were when they said that .NET was the important thing and languages like Visual Basic and C# are just the glue that holds programs together. The .NET Framework was a revelation. I had never used anything quite like it. What the framework really consists of is a huge number of methods, data types and objects that are available to all of your programs. This means you don't have to reinvent the wheel all of the time. Whenever you find yourself trying to do something complicated, it's well worth hunting through the help files, because the .NET Framework probably contains something that will simplify your program greatly. You use the exact same .NET functions regardless of whether you use Visual Basic 2005 or C#, or any other .NET language for that matter.
The .NET Framework is organized into sections in a hierarchy.
For example, anything involving file input and output is in the
System.IO "namespace". Anything to do with file paths, such as finding
the directory from a full path, is
in System.IO.Path. Specifically, finding the extension of a file is
done with System.IO.Path.GetExtension()
. On
the other hand, if you want
to interact with the internet, you will find all you need in the
System.Net namespace.
One thing I loved about the old BASIC was its simple string handling. The .NET Framework has excellent text handling capabilities. My favourite was the StringCollection object, which is a bit like an array except that you don't have to worry about using numbers to access the strings stored in it (though you can if you really want). You can just add strings to the StringCollection, then work on them using a For Each loop, which will step through all of the strings no matter how many or few there are.
Much of the Framework treats files as one-way streams of bytes or characters, which you can read and write with the StreamReader and StreamWriter objects. I found this to be a pretty simple way of doing things. You can either read a number of bytes, the whole file, or for text files you can read a line at a time. Many objects use streams for input and output, so for example if you are uploading a file with FTP, you write the file to an FtpWebRequest object's stream with a StreamWriter.
XML files can either be treated as one-way streams with XmlReader and XmlWriter, or you can load the whole XML file into an XmlDocument, and create an XPathNavigator to hop back and forth through the document. I used the .NET Framework's XML handling facilities quite extensively. The basics of reading and writing XML are very simple, and there are a lot of code examples in the help files. Although the advanced features are complicated and take a while to learn, they give you a hugely powerful way to manipulate XML data.
If you are using a part of the framework a lot, you can save
on typing by "importing" that namespace. If you write imports
System.IO.Path
then all of System.IO.Path becomes
available. You could
then just write GetExtension()
instead of
System.IO.Path.GetExtension()
.
One interesting side effect of the .NET Framework is that once you have used it with Visual Basic 2005, you can understand many code samples written in C# even if you have done little or no programming in the language. This is because a lot of samples and tutorials are really explaining how to use the .NET Framework, and the language doesn't matter. In fact, the extra step of working out the translation from C# to VB 2005 makes you slow down a little and think about the code, rather than just copying it and pasting it. Although Microsoft have made a great effort to write code samples in Visual Basic 2005, there is a lot of stuff out there in C#, and I found myself using it to help write my own programs.
If you choose to learn VB 2005, your .NET knowledge will be transferable to other .NET languages such as C#. If there is an old VB way of doing things, and a .NET way, then it's well worth looking up the .NET way. Then you will find it very simple to read code written in C#, or even start programming in C# yourself.
All programs written in a .NET language need the right version of the .NET runtime to be present on the computer. VB 2005 uses the .NET Framework version 2.0, and you can't set it to use an earlier version. I noticed that a lot of useful functions were new to version 2.0. The runtime is a 22.4MB download, nothing much if you have a broadband connection but a big download on dialup. It's something you might have to consider.
Next I will talk about the My namespace.