Ozeki 10 SMS Gateway

Visual Basic tutorial: Hello world

This tutorial helps you get started with Visual Basic. It explains what you need to write your first Visual Basic program. It starts with the basics: you will learn where you can find and download the tools needed, how to install these tools and it will take you all the way to building and runing your code. If you have never written a Visual Basic program before this is the place to start. We have created this article, so you can get started with Visual Basic, and move on to our sms examples. If you are already familiar with Visual Basic, you can jump directly to one of the following SMS projects.

VB sms examples:

VB send sms with the HTTP rest api (code sample)
VB send multiple sms with the HTTP rest api (code sample)
VB schedule sms with the HTTP rest api (code sample)
VB receive sms with the HTTP rest api (code sample)
VB delete sms with the HTTP rest api (code sample)
Download the latest Visual Basic sms api library from Github

What is Visual Basic

Visual Basic is a programming language. It is similar to a natural language, like English. It is used to talk to a computer. The major difference between a natural language and a programming language is that, programming languages have a more rigorous structure, to help the computer understand it better.

What is Visual Studio

Visual studio is a tool to write a Visual Basic program. Visual studio allows you to type in text using the Visual Basic language, and it makes it possible for you to tell the computer, to read the text and execute the instructions. We use the term "Run" to tell computer to execute the instructions.

What is a Visual Basic Hello world program

The Visual Basic hello world program is the most simple program you can write. It simply prints out the sententce: Hello world on the computer screen. The Hello World program is the first program developers write in any programming language.

How to write your first program in Visual Basic

To write your first program in Visual Basic:

  1. Setup Visual Studio
  2. Create a new Visual Studio project
  3. Select Console Application
  4. Name the project
  5. Choose .NET for Target Framework
  6. Write Hello World program in Visual Basic
  7. Run the Hello World program
  8. Check the output

Prerequisites

Here is what you need to get started. To write your first computer program in Visual Basic, you need a Windows computer, the Visual Studio programming environment and example code presented below.

  • Windows 10 computer
  • Microsoft Visual Studio Community Edition
  • Ozeki Hello World example project

Download Visual Studio

Microsoft Visual Studio Community Edition

In this video tutorial you will find how to download the Visual Studio Community Edition installer. You may download the installer from the following URL: https://visualstudio.microsoft.com/downloads/. On this page you will see different version of Visual Studio available for download. Follow the instructions in this short video to download the installer on to your computer.

Install Visual Studio

To write your first Visual Basic program, you need to install Visual Studio. The following video shows you how this installation can be done.

Create your first visual studio project

After Visual Studio has been installed, you need to open it, and create a console project. The console project is the most simple project you can create.

Create a new project

First, open Visual Studio, which you have just installed. You will be then greeted by a welcome screen. This screen lets you create a new project or open previous ones. Under the "Get Started" column on the right, click on Create a new project (Figure 1). This will forward you to the next page where you can configure the settings of your project.

create new project
Figure 1 - Create new project

Choose VB Console Application

After you have clicked on "Create a new project" you will be brought to a configuration screen. In order to create an Visual Basic, you will first need to select the Visual Basic Console Application template (Figure 2). Click on this option to select it. Then, click on the Next button on the bottom left to continue.

console application
Figure 2 - Choose VB Console Application

Name your project

After specifying your project as a Console Application, you will be asked to give it a name. Under the text that reads "Project name" you will find a textbox (Figure 3). Enter your desired name into this textbox to name your project. Give it an easily identifyable and fitting name, so you could always recognize it. Click on the Next button on the bottom right when you are done.

project name
Figure 3 - Write the project name

Choose target framework

To finalize your project configuration you need to select a targeted framework. This can be done on the last configuration page. You can select a targeted framework from the combobox by clicking on it (Figure 5). Here we select .NET Core 3.1. This is a good choice for your project. Click on the Create button on the bottom right to create your project.

target framework
Figure 4 - Target framework

Write your 'hello world' program in Visual Basic

The first program you write in any programming language is the 'Hello world' program. The sole aim of this program is to print the term 'Hello world' to the computer screen. In this example the program consists of two lines of code: The first line: Console.WriteLine prints the text.

Imports System

Module Program
    Sub Main(args As String())
        Console.WriteLine("Hello World!")
    End Sub
End Module

Output of your code

This video shows you how the output of your code will appear after you ran it. After your program finishes running, you will se the "Hello World" message printed on the top. It also closes the program with exit code 0. To close the window too, press any key on your keyboard.

Run the Visual Basic 'hello world' program

To run the hello world program, you need to click on the green Start button in the Visual Studio toolbar. You may also use the F5 key to run your program. Note that when you press F5, visual studio will first save your newly written file, then it will copmile it to an executable code, and then it will run it on your computer.

Run the program

To run the hello world program, you need to click on the green Start button in the Visual Studio toolbar. This executes the code you wrote in the text editor on your computer. It will open a new window where you can view the output of your code (Figure 5).

run the program
Figure 5 - Run the program

"Hello World!" output

After you have instructed Visual Studio to run you program a debug console will pop up. In this debug console you can see your program run in real time. This looks very much like a regular Windows command prompt. The first line you see is the output of your code: "Hello World" (Figure 6). Then, 3 lines further down, you will see "exited with code 0". This means your program has closed. To close the console itself, press any key on your keyboard.

cmd
Figure 6 - Hello World!

What happens if I make a mistake in Visual Basic

If you make a mistake, when you write your instructions in Visual Basic, you will get a Syntax error. The computer will highlight the line with error in red, and it will tell you why didn't it understand the instructions. To correct the mistake you need to go back to the text editor and modify the program. Programs say they "fix the error" when they correct mistakes.

What is syntax error in Visual Basic?

Syntax error means I don't understand. If you talk to somebody in English and he does not understand what you say, he will reply with "I don't understand". If you talk to a computer in Visual Basic and the computer does not understand what you say, he will reply with "Syntax error".

In this video below we will create a mistake intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

How to handle a syntax error in VB?

In the code below we will create a syntax error intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

Errors in Visual Basic

When you make a mistake in the code, there are multiple ways Visal Basic will notify you. First of all, lines that will lead to errors are underlined in red in the text editor (Figure 7). If you decide to run the program anyway, the Output console on the bottom of the screen will list all of the errors. These listings contain an explanation of the problem itself, so it is easier for the programmer to identify the problem and fix it.

error
Figure 7 - Error

Summary

Now that you have completed the five simple steps above, you have made your first step in becoming a VB.Net software developer. This program may seam simple, and it may not do much, but this is how great things start. The next step in your learning jorney will be creating an HTTP request.

More information