|
Many people are in the process of learning VB.NET so I wrote this VB.NET tutorial to teach you some basic things about how to write your first application using VB.NET. Lets check it out. As with any tutorial this VB.NET tutorial is not completly exhaustive. This just covers the basics and soon I will write more VB.NET tutorials to cover more. Enjoy!
Lets write a simple hello world VB.NET program:
First start Microsoft Visual Studio 2005. In the menu bar select File -> New -> Project.
Choose Visual Basic -> Windows -> Windows Application
Type in a name for this program. For this VB.NET Tutorial we will use the name HelloWorld. Then click OK and your program will be created.
Press F5 and the program should run. You will see a blank window that says Form1 at the top. You can move the window around, minimize it, and press the x button to close it. Already we have a pretty amazing program when you think of the fact that to write all this in C you would have thousands of lines of code.
Now lets make the program do something. Its time for this VB.NET Tutorial to say 'Hello, World!'
To begin you must have the toolbox window open. If you don't see it on your screen simply select View -> Toolbox in the menu bar or press Ctrl-Alt-X.
In the Toolbox under the All Window Forms tree, double click the Button object. This will place a button on your form designer labelled Button 1. Drag the button to wherever you would like.
Now Double click the Button1 in the form designer. This will add an event called Button1_Click. If its not obvious to you this event gets called anytime the user clicks on button one. What we wan't are VB.NET Tutorial program to do is say 'Hello, World!'. An easy way to accomplish this is to display a messagebox with that phrase in it. For those of you who are familiar with the older versions of Visual Basic the way we would accomplish this is by using the MsgBox command. VB.NET does not have this command, but we can accomplish a similiar thing by using the MessageBox.Show command. Check out the code below:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show("Hello, World!")
End Sub
End Class
This is actually a much more powerfull command than the old Visual Basic one. We are only using a very small part of its features. Basically all we have specified is what text to display in the messagebox. We could also specify the caption for the message box using the following command.
MessageBox.Show("Hello, World!", "VB.NET Tutorial")
With this command we would see a message box appear that not only says Hello, World!, but also has a title of VB.NET Tutorial at the top of it. Other features of the MessageBox.Show command include setting what buttons appear, changing the icon that the box has, and many other things.
So lets try this thing out. If you press F5 you will again see your Form1 appear than if you click the Button a message box will appear saying Hello, World. If you added the second paramater the message box will also have a caption that says VB.NET Tutorial.
The links bellow might help you discover more to do with VB.NET.
|