Tutorial - Create A Simple Visual Basic (VB) Console App - Visual Studio (Windows) - Microsoft Docs
Tutorial - Create A Simple Visual Basic (VB) Console App - Visual Studio (Windows) - Microsoft Docs
Docs
/
Visual Studio
/
IDE
/
Getting Started (Visual Basic)
/ D /
In this article
Prerequisites
Create a project
Run the app
Add code to ask for user input
Extra credit: Add two numbers
Add Git source control
Clean up resources
Next steps
See also
Applies to: Visual Studio Visual Studio for Mac Visual Studio Code
This article shows how you'll use Visual Studio to create a simple Visual Basic
application, a console app. In this app, you ask the user for their name, and then display
it back with the current time. You'll also explore some features of the Visual Studio
integrated development environment (IDE), including source control in Git. Visual Basic
is a type-safe programming language that's designed to be easy to learn. A console app
takes input and displays output in a command-line window, also known as a console.
Prerequisites
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 1/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
If you haven't already installed Visual Studio, go to the Visual Studio downloads page
to install it for free.
Create a project
First, you'll create a Visual Basic app project. The default project template includes all
the files you'll need for a runnable app.
3. In the Create a new project window, choose Visual Basic from the Language list.
Next, choose Windows from the Platform list and Console from the Project types
list.
After you apply these language, platform, and project type filters, choose the
Console App template, and then choose Next.
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 2/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
7 Note
If you do not see the Console App template, you can install it from the Create
a new project window. In the Not finding what you're looking for? message,
choose the Install more tools and features link.
Then, in the Visual Studio Installer, choose the .NET desktop development
workload.
After that, choose the Modify button in the Visual Studio Installer. You might
be prompted to save your work. Next, choose Continue to install the
workload. Then, return to step 2 in this Create a project procedure.
4. In the Configure your new project window, enter WhatIsYourName in the Project
name box. Then, choose Next.
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 3/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
After you select your Visual Basic project template and name your project, Visual Studio
creates a Program.vb file. The default code calls the WriteLine method to display the
literal string "Hello World!" in the console window.
There are two ways to run this code, inside Visual Studio in debug mode, and from your
computer as a regular standalone app.
1. Select the WhatIsYourName button or press F5 to run the default code in Debug
mode.
2. When the app runs in the Microsoft Visual Studio Debug Console, "Hello World!"
displays. Press any key to close the debug console window and end the app:
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 5/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
4. The Main procedure terminates after its single statement executes and the console
window closes immediately. To keep the console visible until the user presses a
key, see the next section.
1. Enter the following Visual Basic code after the Sub Main(args As String()) line
and before the End Sub line, replacing the WriteLine line:
VB = Copy
Console.ReadKey(True)
2. Select the WhatIsYourName button or press F5 to build and run your first app in
Debug mode.
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 6/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
3. When the debug console window opens, enter your name. Your console window
should look similar to the following screenshot:
4. Press any key to end the app, and then press any key to close the debug console
window.
Now that your new code is in the app, build and run the executable (.exe file) in a
system console window, as described previously in Run the app as a standalone. Now
when you press a key, the app exits, which closes the console window.
VB = Copy
Module Program
Console.ReadKey(True)
End Sub
End Module
to:
VB = Copy
Module Program
num1 = Console.ReadLine()
Console.Write("Type another number to add to it and press Enter")
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 7/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
num2 = Console.ReadLine()
answer = num1 + num2
Console.ReadKey(True)
End Sub
End Module
And then run the updated app as described under "Run the app".
Tip
Git is the most widely used modern version control system, so whether you're a
professional developer or you're learning how to code, Git can be very useful. If
you're new to Git, the https://git-scm.com/ website is a good place to start.
There, you can find cheat sheets, a popular online book, and Git Basics videos.
To associate your code with Git, start by creating a new Git repository where your code
is located:
1. In the status bar at the bottom-right corner of Visual Studio, select Add to Source
Control, and then select Git.
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 8/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
The repository name auto-populates based on your folder location. Your new
repository is private by default, which means you're the only one who can access
it.
Tip
After you create your repository, you see status details in the status bar.
The first icon with the arrows shows how many outgoing/incoming commits are in
your current branch. You can use this icon to pull any incoming commits or push
any outgoing commits. You can also choose to view these commits first. To do so,
select the icon, and then select View Outgoing/Incoming.
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 9/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
The second icon with the pencil shows the number of uncommitted changes to
your code. You can select this icon to view those changes in the Git Changes
window.
To learn more about how to use Git with your app, see the Visual Studio version control
documentation.
Clean up resources
If you're not going to continue to use this app, delete the project.
Next steps
Congratulations on completing this tutorial! To learn more, see the following tutorial.
Build a library with Visual Basic and the .NET Core SDK in Visual Studio
See also
Visual Basic language walkthroughs
Visual Basic language reference
IntelliSense for Visual Basic code files
Recommended content
Tutorial: Create a Windows Forms app with Visual Basic - Visual Studio
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 10/11
7/11/22, 8:31 PM Tutorial: Create a simple Visual Basic (VB) console app - Visual Studio (Windows) | Microsoft Docs
(Windows)
In this tutorial, learn how to create a Windows Forms app in Visual Studio with Visual Basic.
Show more S
https://docs.microsoft.com/en-us/visualstudio/get-started/visual-basic/tutorial-console?view=vs-2022 11/11