Skip to content
Variables and Conversions
step 1/5

Reading — step 1 of 5

Learn

~1 min readBasics

Declare with Dim:

Dim age As Integer = 36
Dim name As String = "Ada"
Dim pi As Double = 3.14159
Dim isActive As Boolean = True

As Type is required (with Option Strict On, which is the recommended setting).

Common types:

  • Integer (32-bit), Long (64-bit), Short (16-bit), Byte
  • Double, Single, Decimal
  • Boolean (True/False)
  • String
  • Char (single character — note: separate from String!)

String operations:

Dim s As String = "hello"
Dim upper As String = s.ToUpper()             ' "HELLO"
Dim len As Integer = s.Length                  ' 5
Dim greeting As String = "Hello, " & s & "!"  ' & for concat
Dim formatted As String = $"{name} is {age}"   ' interpolation

& is the canonical concat (also + works for strings, ambiguously). Modern interpolation $"...{x}..." matches C# 6+.

Conversion:

Dim n As Integer = Integer.Parse(Console.ReadLine())

Discussion

Ask a question, share an insight, or help someone who’s stuck.

Sign in to post a comment or reply.

Loading…