Visual Basic

How To Create A Visual Basic Application

To create a Visual Basic application, install Visual Studio with the .NET desktop development workload, create a Visual Basic Windows Forms project, and design a form using controls from the Toolbox. Add code that responds to user actions, run and debug the application, then publish.

Which licences fit your PC setup?

Prices are an AUD snapshot, not a live quote. Confirm variant and total on the listing.

Choose a small Windows desktop project

This walkthrough builds a greeting application: the user types a name, clicks a button and sees a message. It introduces the essential workflow without requiring a database or an external service.

The instructions use Visual Basic for .NET and Windows Forms on Windows. If you need an explanation of the language before starting, read what Visual Basic code is.

Install the tools and create your project

  1. Install Visual Studio on your Windows computer. In the installer, select the .NET desktop development workload, which provides the desktop application tools.
  2. Open Visual Studio and select Create a new project. Search for Windows Forms App and filter the language to Visual Basic.
  3. Select Windows Forms App for .NET. The similarly named Windows Forms App (.NET Framework) template targets a different framework; use it when an existing application's requirements call for it.
  4. Name the project GreetingApp, choose a folder you can find again and select a supported .NET target offered by your installation. Create the project.

If the template is missing, reopen Visual Studio Installer and check that the desktop workload is installed. Microsoft's Windows Forms setup walkthrough shows the project creation screens.

Visual Studio creates a default form, usually named Form1. Solution Explorer lists the project files, the designer lets you arrange controls, and the Properties window lets you change the selected object's settings.

Design the greeting form

A form is the application's window. Controls are the elements inside it, such as text boxes, buttons and labels. Open Form1 in the designer, then open Toolbox and Properties from the View menu if they are hidden.

  1. Select the form and set its Text property to Greeting App. This changes the window title.
  2. Drag a Label onto the form and set its Text property to Enter your name.
  3. Add a TextBox below that label. Set its (Name) property to txtName.
  4. Add a Button. Set its (Name) to btnGreet and its Text to Show greeting.
  5. Add another Label below the button. Set its (Name) to lblGreeting and its Text to Your greeting appears here.

The Name property identifies a control in your code; Text determines what the user sees. Set the names before writing the event handler so that the example matches your controls.

Leave enough space for the output label to display a longer name. Arrange the input, button and result in reading order, and set their TabIndex properties so keyboard navigation follows that order.

Add code to the button's Click event

A Windows Forms interface responds to events. Clicking a button raises its Click event, and an event handler contains the instructions that run in response. Other events include text changes and form loading.

  1. Double-click the Show greeting button in the designer. Visual Studio opens the form's code file and generates a handler for the button's Click event.
  2. Inside that handler, between the Private Sub line and End Sub, enter the following statement.

lblGreeting.Text = "Hello, " & txtName.Text.Trim()

This reads the text box, removes spaces from either end of the name and joins it to the greeting. The result becomes the output label's Text. Enter the statement inside the generated procedure, rather than replacing the surrounding form class or handler declaration.

You do not need a variable for this single assignment. As the application grows, variables can hold values used in several operations. The guide to what Dim means in Visual Basic explains how to declare them.

Run the application and investigate errors

  1. Save the project and select Debug > Start Debugging, or press F5.
  2. Type a name and click Show greeting. Check that the label displays the greeting followed by the name.
  3. Try leading and trailing spaces, a long name and an empty text box. The first version displays Hello, without a name when the input is empty; decide how you want to handle that case.
  4. Close the application window to finish the debugging session before making further changes.

Fix build errors before testing behaviour

If the project will not build, read the Error List. Check spelling, quotation marks and control names first. For example, txtName in the statement must match the text box's Name property.

If the app runs but clicking the button does nothing, check that the statement is in the handler connected to btnGreet.Click. Set a breakpoint beside the statement and click the button again. When execution pauses, inspect txtName.Text to see the actual input.

For later features, validate input before processing it. Use Try...Catch for failures you can meaningfully handle, such as an unavailable file, and give the user a useful recovery message.

Publish the app for another computer

A successful run in Visual Studio does not verify that the application will work elsewhere. Publishing prepares the application and its dependencies for distribution.

  1. Select the Release build configuration and build the project. Resolve any errors.
  2. Right-click the project in Solution Explorer and select Publish. Choose a folder destination for a straightforward first deployment.
  3. Review the target Windows architecture and deployment mode in the publishing settings, then publish.
  4. Copy the complete published output to a separate Windows test environment and check that it starts and performs the greeting task.

A framework-dependent deployment requires a compatible .NET Desktop Runtime on the destination computer. A self-contained deployment includes the runtime, increasing the files you distribute. Microsoft's .NET publishing guidance explains these options. Avoid distributing only the executable unless your publishing configuration explicitly produces the required standalone package.

Add one useful improvement

Next, add a condition that checks for empty or whitespace-only input and asks the user to enter a name. Test that case again before adding more features. You can then explore layouts that resize cleanly, saving data or connecting to services through the Visual Basic guides.

Other editions for separate workloads

Other editions for separate workloads; prices in AUD, confirm the total on the listing.

How to check this worked

  1. Open Settings, System, Activation and confirm the edition shown.
  2. Enter the key and run activation; expect a green tick within a minute.
  3. Reboot and re-check activation survives the restart.

FAQ

What else should you know before buying?

What do I need before starting?
Read the requirements and confirm the edition first; the steps assume the machine is compatible.
How do I know the licence is genuine?
Activate on Microsoft's servers and check Settings, System, Activation. A working activation is the test.
Is this a subscription?
Keys sold here are one-time lifetime licences. Microsoft 365 plans are billed by Microsoft instead.
What if the key fails?
Email hi@ms.codes with the order number and a screenshot. Replacement or refund applies within 30 days.

Check who prepared and reviewed this guide

Written by
MS.Codes editorial
Reviewed by
Support team

Last verified: (source review; see test status above).

Recent Post