Hello World, your first Visual Basic application

Your first Visual Basic Application will be the classic Hello World application in Visual Basic. I’m not sure why Hello World has become such a ubiquitous example. It’s been around since 1974, when it appeared in the absolute classic book, “The C Programming Language” by Brian Kernighan and Dennis Ritchie, who are affectionately known as K&R. (You can always tell someone has made it when they get a nickname…) and the Hello World Program has been adapted to every language known to man since then.

Here’s the Visual Basic version.

Open Visual Studio. I’m using Visual Studio 2010 but don’t be put off by that, use whatever version you have. Create a New Project by clicking the link as shown below Visual Basic Tutorial - Create New Project Clicking the New Project link will open up the New Project window as shown below. Make sure you select Visual Basic from the list of Templates and Windows Forms Application as the type of application you want the project to create. Call the project Hello World. Visual Basic Tutorial - Hello World - New Project

To be more specific you’ve created a project that will ultimately create a desktop application.  A desktop application is a type of application that sits on the end users computer, much like Word or Excel. As opposed to a web application which is essentially a website you view in your browser.

 

So what exactly is a project? A Project in Visual Basic is an area which stores and organises every item of your application. It’s a bit like a folder in Windows Explorer. You’ll see the Project by default in the top right hand of the screen. It contains all the files which make up your project. In Visual Basic.NET it’s called the Solution Explorer.
visualbasictutorialsolutionexplorer Other than the Solution Explorer your screen is composed of 3 main elements. We will go describe them in more detail throughout this guide but you will see 1. The menu and toolbar Visual Basic Tutorial - MEnu 2. The Properties Window visualbasictutorialproperties 3. The Form Designer visualbasictutorialform The Form Designer is where we will concentrate our efforts today. A Form represents each of your screens in Visual Basic application. Your Visual Basic Form has two views, a Design view and a Code view. Using the Design view you can add controls to this form to create incredibly rich applications. For now though, double click on the form to open the code view. Enter the following code so the Form Load Event looks as follows (obviously leaving the Form1_Load line as is)

Private Sub Form1_Load(ByVal sender As ....

     MessageBox.Show("Hello World!!")

End Sub

You can run your program in one of three ways 1. Press F5 2. Press the Green Arrow in the toolbar 3. Select the Debug >> Start Debugging Menu Option Try one of these and you should see the following as soon as the program loads helloworldmessagebox

Congratulations! You have developed, compiled and run your first Visual Basic application. You’ve also joined the ranks of every software developer worldwide.  Every single one of us has created a Hello World application at some stage in our careers.  Don’t worry too much about understanding what’s happening yet. All will become clear as we progress through these tutorials.

If you’d like a recap, or prefer your tutorials visually then press play in the video below.