VB .NET Uncovered: Getting Started
So you've created a new Windows Application project, huh?
Now, I'll be the first to admit the development environment does look a little different from those halcyonic days of Visual Basic 6. But if you take a few minutes to study it, you'll notice it's actually pretty much the same.
To the left of the screen, you have the Toolbox, full of controls. You'll notice a few favourites in there: the Label control, the TextBox, the PictureBox. And a few have been renamed, such as the Radio Button (formerly Option Button), GroupBox (aka Frame) and of course, Button (of Command Button fame).
You'll also spot a whole load of new controls there. We'll look at these in more detail later — but they're actually not as scary as they first appear! ;)
To the right of your screen, you have the Properties window, which doubles up as a Help facility. Plus, just above that you'll find what was previously the 'Project Explorer'. This keeps a track of all the files and references within your app.
And finally, in the centre of your screen you'll find Form1 ahhh, just like ol' VB6.
So, let's do something!
- Add a Button to Form1, just as you would in VB6
- Double-click on the Button
Arghhhh! What's all that code?
You've just double-clicked on the Button and a whole load of pre-written code has popped up. Where? Who? Why? Well, it's essentially code that tells the form how to build itself, but ignore it for now.
Your cursor should be flashing between:
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) End Sub
Now, this is similar to our old Command1_Click() sub, though a perhaps a little more complex.
Type in the following code:
MessageBox.Show("Hello World!", "My First App")
Top Tip: As you type this code out, notice that Visual Basic doesn't change the casing automatically! So if you type 'MESSAGEBOX', it won't automatically convert it to the proper casing of 'MessageBox'. I don't like this feature and hope they switch casing back on in Beta Two.
Another Top Tip: Whilst the MsgBox statement still exists, MessageBox.Show is the next hip and trendy way to display one of 'em.
- Press F5 to test your code
After a little more whirring your form should popup.
- Click the Button to display your Message Box
Your form should look something like this:
And that's it! Hurrah and congratulations on creating your first VB.NET application!
We'll be looking in more detail at 'Windows Forms' and VB.NET code in the next instalment, but for today, it's time to wrap up.
Page 5 of 6