Breaking News
You are here: Home / Notes / SEM-4 / .NET PROGRAMMING / Variables in

Variables in



A variable is nothing but a name given to a storage area that our programs can manipulate. Each variable in VB.Net has a specific type, which determines the size and layout of the variable’s memory; the range of values that can be stored within that memory; and the set of operations that can be applied to the variable.

We have already discussed various data types. The basic value types provided in VB.Net can be categorized as:

Type Example
Integral types SByte, Byte, Short, UShort, Integer, UInteger, Long, ULong and Char
Floating point types Single and Double
Decimal types Decimal
Boolean types True or False values, as assigned
Date types Date
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

Variables are initialized (assigned a value) with an equal sign followed by a constant expression. The general form of initialization is:

variable_name = value;


for example,

Dim pi As Double
pi = 3.14159


You can initialize a variable at the time of declaration as follows:

Dim StudentID As Integer = 100
Dim StudentName As String = "Juned Ansari"



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)
   End Sub
End Module


How Accepting Values from User?

The Console class in the System namespace provides a function ReadLine for accepting input from the user and store it into a variable. For example,

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



Download Paper Solutions from Below Link

About admin

Scroll To Top