Values in Visual Basic .NET

Visual Basic .NET has various value types including strings, integers, floats, booleans, etc. Here are a few basic examples.

Imports System

Module Values
    Sub Main()
        ' Strings, which can be concatenated with &
        Console.WriteLine("Visual Basic" & ".NET")

        ' Integers and floats
        Console.WriteLine("1+1 = " & (1 + 1))
        Console.WriteLine("7.0/3.0 = " & (7.0 / 3.0))

        ' Booleans, with boolean operators as you'd expect
        Console.WriteLine(True And False)
        Console.WriteLine(True Or False)
        Console.WriteLine(Not True)
    End Sub
End Module

To run the program, save it as Values.vb and use the Visual Basic compiler:

$ vbc Values.vb
$ mono Values.exe
Visual Basic.NET
1+1 = 2
7.0/3.0 = 2.3333333333333335
False
True
False

In this example, we’ve demonstrated:

  1. String concatenation using the & operator.
  2. Basic arithmetic operations with integers and floating-point numbers.
  3. Boolean operations including AND, OR, and NOT.

Note that Visual Basic .NET uses Console.WriteLine for output instead of fmt.Println. Also, the & operator is used for string concatenation rather than +.

The boolean operators in Visual Basic .NET are written as And, Or, and Not, which are more verbose than their counterparts in some other languages.

This example provides a basic introduction to working with values in Visual Basic .NET. As you continue to explore the language, you’ll encounter more complex data types and operations.