How to Generate QR Code in VB .NET

QR Code, or Quick Response Code, have evolved into versatile format for storing and retrieving information. Widely used in diverse fields, from marketing to product labeling, QR Code images offer a quick and efficient means of accessing information through a simple scan of the picture box.

In this article, we'll explore how to generate VB.NET QR Code barcodes within a Console Application, employing the IronQR library.

IronQR

IronQR, a robust C# Quick Response Code system library, extends its support to VB.NET developers for QR Code barcode generation and reading QR Code. Despite being primarily designed for C#, IronQR seamlessly integrates with VB.NET, as it is built upon .NET Framework, providing an accessible way to incorporate its functionality to easily create QR Code barcodes using VB.NET. Its simplicity and extensive feature set make it an ideal choice for developers seeking efficient VB.NET QR Code barcode generator solutions.

Prerequisites

Before delving into the coding process to create QR Code in VB.NET, ensure you have the required tools in place:

  1. Visual Studio: Make sure Visual Studio is installed on your system. If not, download it from the official website.

    1. IronQR Library: Install the IronQR library using the NuGet Package Manager in VS. Execute the following command in the Package Manager Console:
    
    PM > Install-Package IronQR
    
    PM > Install-Package IronQR
    'INSTANT VB TODO TASK: The following line uses invalid syntax:
    'PM > Install-Package IronQR
    VB   C#

    This command installs the necessary packages for working with IronQR in your VB.NET project.

## Creating a Console Application

Let's start by setting up a simple VB.NET Console Application:

1. Open Visual Studio and choose "Create a new project."

  2. Select "Console App" as the project template and click "Next."

![How to Generate QR Code in VB .NET: Figure 1 - Console App- QR Code Generator](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-1.webp)

  3. Configure the project settings and click "Next."

![How to Generate QR Code in VB .NET: Figure 2 - Project Configuration](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-2.webp)

  4. In Additional information, select the latest .NET framework.

![How to Generate QR Code in VB .NET: Figure 3 - .NET Framework](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-3.webp)

5. Click "Create" to generate your VB.NET Generate QR Code application.

## Install IronQR Library using Solution Explorer

1. With the project set up, click on Solution Explorer, and select Manage NuGet Packages for Solution.

![How to Generate QR Code in VB .NET: Figure 4 - Manage NuGet Packages for Solution](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-4.webp)

1. In the NuGet window, click the Browse tab and search for IronQR and click Install button.

![How to Generate QR Code in VB .NET: Figure 5 - IronQR- Generate QR Code VB (.NET)](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-5.webp)

## Implementing QR Code Generator in VB.NET

In this QR code generation application, we'll showcase the simplicity and flexibility of generating QR Code using the IronQR library within a (Visual Basic) VB.NET Console Application. We begin with the most straightforward approach, [**creating a QR code**](/csharp/qr/examples/generate-qr-code/) with a default configuration. Then, we move to a more advanced QR Code example, customizing parameters such as the QR code's content, logo, size, and version. For more code example, please visit [**QR code generator for .NET**](/csharp/qr/tutorials/csharp-qr-code-generator/).

Let's explore the below sample code snippet and understand how IronBarcode simplifies QR Code, barcode image generation in Visual Basic.

```cs
Imports IronQr
Imports IronSoftware.Drawing
Imports Color = IronSoftware.Drawing.Color
Module Program
    ' Simplest example of creating a QR Code with no settings:
    Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
    ' Save QR Code as a Bitmap
    Private qrImage As AnyBitmap = myQrCode.Save()
    ' Advanced Example to set all parameters:
    ' The value of the QR Code as a string. Also suitable for URLS.
    Private value As String = "https://ironsoftware.com/"
    ' Set QR options
    Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
    ' Create a QR Code object
    Private myQr As QrCode = QrWriter.Write(value, options)
    ' Fancy style options
    Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
    Private style As New QrStyleOptions With {
        .Dimensions = 300,
        .Margins = 10,
        .Color = Color.Gray,
        .Logo = New QrLogo With {
            .Bitmap = logoBmp,
            .Width = 100,
            .Height = 100,
            .CornerRadius = 2
        }
    }
    ' Save QR Code as a Bitmap
    Private qrImageComplex As AnyBitmap = myQr.Save(style)
    Sub Main(args As String())
    IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
        qrImageSimple.SaveAs("simpleQRCode.png")
    qrImageComplex.SaveAs("complexQRCode.png")
    End Sub
End Module

Let's break down the above source code for creating QR Code images step by step:

  1. Imports Statement:

    
    Imports IronQr
    Imports IronSoftware.Drawing
    Imports Color = IronSoftware.Drawing.Color
    
    Imports IronQr
    Imports IronSoftware.Drawing
    Imports Color = IronSoftware.Drawing.Color
    'INSTANT VB TODO TASK: The following line uses invalid syntax:
    '@Imports IronQr @Imports IronSoftware.Drawing @Imports Color = IronSoftware.Drawing.Color
    VB   C#

    These lines import the necessary namespaces from the IronQR library, providing access to the classes and methods required for QR Code generation and styling.

  2. **Module Declaration:** 

    ```cs
Module Program
The **Module** keyword declares a module named "Program," encapsulating the code. A module is a container for organizing code in VB.NET.
  1. Create QR Code - Simple Source Code Example:

    
    ' Simplest example of creating a QR Code with no settings:
    Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
    ' Save QR Code as a Bitmap
    Private qrImage As AnyBitmap = myQrCode.Save()
    
    ' Simplest example of creating a QR Code with no settings:
    Private myQrCode As QrCode = QrWriter.Write("https://ironsoftware.com/")
    ' Save QR Code as a Bitmap
    Private qrImage As AnyBitmap = myQrCode.Save()
    'INSTANT VB TODO TASK: The following line uses invalid syntax:
    '' Simplest example @of creating a QR Code @with no settings: @Private myQrCode @As QrCode = QrWriter.Write("https://ironsoftware.com/") ' Save QR TryCast(Code, a) Bitmap @Private qrImage @As AnyBitmap = myQrCode.Save()
    VB   C#

    Here, a simple QR code is created using the **QrWriter.Write** method with a URL ("<https://ironsoftware.com/>"). The result is stored in the **myQrCode** variable. Then this byte data result is saved as AnyBitmap image to save later as PNG, JPG image format.

  4. **QR Code Creation - Advanced Example:** 

    ```cs
' The value of the QR code as a string. Also suitable for URLS.
    Private value As String = "https://ironsoftware.com/"
    ' Set QR options
    Private options As New QrOptions(QrErrorCorrectionLevel.High, 20)
    ' Create a QR Code object
    Private myQr As QrCode = QrWriter.Write(value, options)
    ' Fancy style options
    Private logoBmp As New AnyBitmap("VisualStudioLogo.png")
    Private style As New QrStyleOptions With {
        .Dimensions = 300,
            .Margins = 10,
            .Color = Color.Gray,
            .Logo = New QrLogo With {
                .Bitmap = logoBmp,
                .Width = 100,
                .Height = 100,
                .CornerRadius = 2
            }
    }
    ' Save QR Code as a Bitmap
    Private qrImageComplex As AnyBitmap = myQr.Save(style)
In this advanced sample code example, we declare variables for customizing the QR Code. Here, **value** holds the content of the QR code, we then set the **QrErrorCorrectionLevel** using **QrOptions** class. Value and options are then passed to **QrWriter.Write** to generate QR code. **logoBmp** holds the QR code logo image, and **style** defines its dimensions, margins, color and logo width, height, and rounded corners. Finally, the image is saved as **AnyBitmap** with styling and later as PNG, JPG image format.
  1. Main Method:

    
    Sub Main(args As String())
        IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
            qrImageSimple.SaveAs("simpleQRCode.png")
        qrImageComplex.SaveAs("complexQRCode.png")
    End Sub
    
    Sub Main(args As String())
        IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01"
            qrImageSimple.SaveAs("simpleQRCode.png")
        qrImageComplex.SaveAs("complexQRCode.png")
    End Sub
    'INSTANT VB TODO TASK: The following line uses invalid syntax:
    '@Sub Main(args @As String()) IronQR.License.LicenseKey = "IronQR-MYLICENSE-KEY-1EF01" qrImageSimple.SaveAs("simpleQRCode.png") qrImageComplex.SaveAs("complexQRCode.png") @End @Sub
    VB   C#


    The **Main** method in VB.NET Console Application is the entry point. Set your license key to remove wartermarks from the QR Code logo generated. It calls the **SaveAs** method on **qrImageSimple** and **qrImageComplex**, respectively, to save the generated QR Code as image files ("simpleQRCode.png" and "complexQRCode.png").

## Running the Console Application and View Output

Execute the Console Application, and you should see a success message indicating that the QR Code has been generated and saved.

![How to Generate QR Code in VB .NET: Figure 6 - Output](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-6.webp)

Output of simple QR Code image:

![How to Generate QR Code in VB .NET: Figure 7 - Simple QR Code ](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-7.webp)

Output of complex QR code image:

![How to Generate QR Code in VB .NET: Figure 8 - Complex QR Code](/static-assets/qr/blog/vb-net-generate-qr-code-tutorial/vb-net-generate-qr-code-tutorial-8.webp)

## Conclusion

This article demonstrated the generation of QR Codes using VB.NET and the IronQR library in a Console Application. By following the outlined steps, developers can easily integrate QR Code generation into their VB.NET projects, offering a quick and efficient way to encode information for various applications. Explore IronQR's [**documentation**](/csharp/qr/docs/) for additional customization options and features.

IronQR is a versatile .NET library specializing in QR code operations. It enables QR Code generation, supports styled variations, and recognizes various QR code formats and types. The library excels in saving QR Codes to image formats like JPEG, PNG, BMP, TIFF, and GIF through the SaveAsImage() method, facilitating seamless integration and storage.

For development purposes, IronQR is freely accessible but with a watermark. Commercial use requires a [**license**](trial-license) for users to evaluate its full functionality.