Thursday, 10 December 2009

Writing Your First VB.NET Program

If you have some experience with VB 6, you'll find that Visual Studio has changed as much or more than the rest of the .NET world. And it's changed for the good!

The "Microsoft Press" aspects of our text start to show up here, however. The text makes it seem like the new VS.NET is sooooo good that we have almost been translated into heaven when we use it.

But there are a couple of things that can trip you up.

As we read Chapter 1, I'll try to point out both a few of the hazards as well as going beyond the book to a few things that were not covered.

Hopefully, those of you who had to install VB.NET met with success! While our text is really great at explaining VB AFTER it's installed, it's strangely quiet about all the cartwheels and handsprings you have to do to get it installed. Most of the installation problems are there to make sure that nobody, but nobody, has a copy of VB that they didn't pay for!!! (Nary a leaf falls upon the Earth but that Microsoft makes a penny of revenue from it's falling!)

The VB.NET solution files, like their counterparts in VB 6, are a repository for the source and compiled versions of the application and also maintain information about the project for Visual Studio. But there are more of them in VB.NET and they're organized in a more complicated directory structure.

For a Windows Application project, you can also browse these XML files:

•Form1.resx
•WindowsApplication1.vbproj.user
And the character based, but not XML files:

•WindowsApplication1.sln
•AssemblyInfo.vb
•Form1.vb
Note that, except for AssemblyInfo.vb, these names will change if the name of the project changes.

The rest of Chapter 1 is all about modifying Properties in the first practice project supplied on the CD with the book, MusicTrivia. But since we're moving on to the creation of our own project in the next chapter, it would be a shame to leave this chapter without also checking out the code in the MusicTrivia project. So let's do that now.

After you have changed the Properties as suggested in the book, make sure that Solution Explorer is visible as shown above and then right-click the MusicTrivia.vb file to display the Context Menu and select View Code. You should see this code. (Note: the two Sub statements have been reformatted to make them fit the web page.)

~~~~~~~~~~~~~~~~~~~~~~~~~
Public Class Form1
Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

Private Sub Button1_Click
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles Button1.Click
Label2().Visible = True
PictureBox1().Visible = True
End Sub

Private Sub Button2_Click
(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles Button2.Click
End
End Sub
End Class
~~~~~~~~~~~~~~~~~~~~~~~~~

At the top of page 20, the book discusses the fundamental nature of Properties and notes that Properties can be set initially (that is, before the program is compiled and run) or while the program is running. The code for the Button1 event subroutine is an example of changing properties while the program is running.

If you "play around" with this code for a while, you'll be very well prepared for the next lesson. So it's a great way to get the jump on learning until the next lesson arrives in your email!

No comments:

Post a Comment