VB.NET Tutorial: Creating Your First Program
Visual Basic .NET is an object-oriented programming language design by Microsoft and typically created using the Microsoft Visual Studio IDE. It is a powerful language that is easy to grasp for beginners and can create functional standalone Windows applications quickly and easily.
VB.NET is considered to be one of the best starting points for people interested in computer programming. The language itself is relatively straightforward and the Visual Studio IDE allows for drag-and-drop functionality in most programming tasks. If you are interested in becoming a computer programmer, VB.NET is an excellent place to start. Before jumping in to this tutorial, you should learn some basic programming concepts like looping and conditional execution from Programming for Non-Programmers: Fundamentals.
Setting up the IDE
Although there are very expensive versions of Visual Studio available from Microsoft, these are designed for large corporations that use VB.NET and other languages such as C# for commercial development. Fortunately, you do not need to purchase this software to start using VB.NET.
Once you have the basics of VB.NET down, C# is a powerful programming language that uses the same IDE as VB.NET. Basic C# with Visual Studio 2013 teaches you the fundamentals of using C#.
Microsoft offers what they call Visual Studio Express: a free version of the powerful IDE that allows you to create VB.NET applications for noncommercial use. You can download Visual Studio Express for free from Microsoft’s website and follow the installation instructions to set up the environment. Installation is very straightforward and does not require any strange configuration steps that are typically required of other IDEs. In other words, it interfaces perfectly with Windows and you should be ready to start creating your first program in no time at all.
Why Use VB.NET?
There are quite a few reasons why beginners and professional programmers choose to rely on VB.NET to create effective programs. Some of these reasons include:
VB.NET is a modern, general-purpose programming language that can be used for a variety of functions.
Just about every programming platform currently used is based on object-oriented principles. VB.NET is no exception.
VB.NET is extremely easy to learn, yet it still provides the high level functionality that is expected of today’s programming languages.
Windows programs have historically been written in C++. Although C++ is still used for many complicated programming task, it is widely considered a difficult language to learn when you are first starting out and has kept many potential programmers from learning how to create Windows applications. VB.NET has torn down this wall and made it easy for anyone to create professional looking Windows applications. If you are interested in learning C++ in the future, the C++ Fundamentals course is an excellent resource.
VB.NET is also used in other common Microsoft products such as Excel. You can learn how to leverage your .NET skills for other products in the Visual Basic for Excel course.
Of course, these are only a few of the reasons why VB.NET is an excellent choice. The fact that Visual Studio Express is free for noncommercial use is also a huge benefit for those people interested in learning how to program without having to spend lots of money on expensive software programs only to find out it’s not really for them.
Creating a Basic Program
Whenever you learn a new programming language, the best way to get started is to… get started. So, without further ado, you are going to create your very first VB.NET program known as “Hello World.”
If you have experience in any other programming language, the Hello World program should be very familiar to you. If this is your first time programming, it is traditional to create this basic program every time you learn a new programming language as it gives you a general idea of how the IDE works and makes sure that you do not have any installation errors that prevent proper compiling of your code.
Start Visual Basic Express and select a new project from the File menu at the top of the screen. A small dialog box will appear asking you what type of project you want to create. Select the Windows Application template. Rename this new project to Hello World and the IDE will automatically create the basis of your new program.
At this point, you will be looking at a Form. A Form in VB.NET is simply another word for an application window. Although the Form on your screen is blank right now, this will become your Windows application in just a few easy steps.
On the left side of your screen, notice the Toolbox. In this toolbox, there are numerous Controls that you can add to your program. A Control in VB.NET is an object that performs some sort of action within your project. Here is where VB.NET makes programming easy. All you need to do is drag the Controls you want onto your Form. Visual Studio Express handles the code required to actually implement these Controls into your program.
You can also resize these Controls once they have been dragged onto the Form. Experiment with positioning them in different places and resizing them as you see fit.
To create the Hello World program, you need two controls. Look for the Button control and the Label control. Drag one of each of these Controls onto your Form and position them where you would like.
The Label will actually display the words “Hello World” when you click on the Button. The only thing left to do at this point is to add the code that tells your program to display “Hello World” when the button is clicked. Fortunately, you do not have to sift through hundreds of lines of code to do this. Simply double-click on the Button and Visual Studio automatically takes you to the event handler for this button.
This view is known as the Code View and it is where you can create program functionality. Notice that some of the code has already been created for you and all you actually have to write is the code to create a subroutine that tells the button and what to do when it’s clicked.
Add the following code into your Code Window:
Public Class HelloForm
Private Sub btnDisplayHello_Click(
ByVal sender As System.Object,
ByVal e As System.EventArgs
) Handles btnDisplayHello.Click
lblHelloWorld.Text = “Hello World”
Please note that some of the code above will already be in place so the easiest thing to do is compare this example with what you see in the Code View and make modifications as necessary. Believe it or not, your program is now ready to run.
To try out your Hello World program, click the Start Debugging icon in the toolbar or simply press F5. When you click the Button, Hello World should be displayed in the label.
Of course, this is a very simplistic version of a VB.NET program, but as previously mentioned, it makes sure that your IDE is set up correctly and gives you an idea of what’s involved in creating your own VB.NET programs.
You can learn a lot from this program by slightly modifying the Controls contained within it and noticing how it affects the function of the program. Try playing around with different settings and see what kind of results you get. The experience you gain can be easily applied to more complicated projects in the future.
VB.NET is a powerful programming language that allows anyone to create Windows applications using a simple, drag-and-drop interface. As is the case with any other programming language, practice is what will transform you into a professional programmer. Fortunately, VB.NET makes it easy and fun.
Top courses in .NET
.NET students also learn
Empower your team. Lead the industry.
Get a subscription to a library of online courses and digital learning tools for your organization with Udemy for Business.