Menu

VB.NET TUTORIALS - VB.Net - Variables

VB.Net - Variables

ADVERTISEMENTS

TypeExample
Integral typesSByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and Char
Floating point typesSingle and Double
Decimal typesDecimal
Boolean typesTrue or False values, as assigned
Date typesDate

ADVERTISEMENTS

Variable Declaration in VB.Net

[  ] [ accessmodifier ] [[ Shared ] [ Shadows ] | [ Static ]]
[ ReadOnly ] Dim [ WithEvents ] variablelist

ADVERTISEMENTS

variablename[ ( [ boundslist ] ) ] [ As [ New ] datatype ] [ = initializer ]

Dim StudentID As Integer
Dim StudentName As String
Dim Salary As Double
Dim count1, count2 As Integer
Dim status As Boolean
Dim exitButton As New System.Windows.Forms.Button
Dim lastTime, nextTime As Date

Variable Initialization in VB.Net

variable_name = value;

Dim pi As Double
pi = 3.14159

Dim StudentID As Integer = 100
Dim StudentName As String = "Bill Smith"

Example

Module variablesNdataypes
   Sub Main()
      Dim a As Short
      Dim b As Integer
      Dim c As Double
      a = 10
      b = 20
      c = a + b
      Console.WriteLine("a = {0}, b = {1}, c = {2}", a, b, c)
      Console.ReadLine()
   End Sub
End Module

Accepting Values from User

Dim message As String
message = Console.ReadLine

Module variablesNdataypes
   Sub Main()
      Dim message As String
      Console.Write("Enter message: ")
      message = Console.ReadLine
      Console.WriteLine()
      Console.WriteLine("Your Message: {0}", message)
      Console.ReadLine()
   End Sub
End Module

Lvalues and Rvalues

Dim g As Integer = 20

20 = g