DATATYPE in a programming language describes that what type of data a variable can hold . When we declare a variable, we have to tell the compiler about what type of the data the variable can hold or which data type the variable belongs to.
Syntax : Dim VariableName as DataType
VariableName : the variable we declare for hold the values.
DataType : The type of data that the variable can hold
VB.NET sample :
Dim count As Integer
count : is the variable name
Integer : is the data type
The above example shows , declare a variable 'count' for holding integer values.
In the variable count we can hold the integer values in
the range of -2,147,483,648 to +2,147,483,647.
The follwing are the some of commonly using datatypes in vb.net.
Boolean
Boolean variables are stored 16 bit numbers and it can hold only True or false.
VB.NET Runtime type : System.Boolean
VB.NET declaration : dim check as Boolean
VB.NET Initialization : check = false
VB.NET default initialization value : false
Integer
Integer variables are stored sighned 32 bit integer values in the range of -2,147,483,648 to +2,147,483,647
VB.NET Runtime type : System.Int32
VB.NET declaration : dim count as Integer
VB.NET Initialization : count = 100
VB.NET default initialization value : 0
String
String variables are stored any number of alphabetic, numerical, and special characters . Its range from 0 to approximately 2 billion Unicode characters.
VB.NET Runtime type : System.String
VB.NET declaration : Dim str As String
VB.NET Initialization : str = "String Test"
VB.NET default initialization value : Nothing
In VisualBasic.Net we can convert a datatype in two ways. Implicit Conversion and Explicit conversion . Also we can convert a type value to a reference and reference value to a type value. These are called Boxing and unBoxing . Boxing referes value type to reference type and unboxing , reference type ot value type.
VB.NET Source Code
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles Button1.Click
Dim check As Boolean
check = True
MsgBox("The value assigned for check is : " & check)
Dim count As Integer
count = 100
MsgBox("The value holding count is : " & count)
Dim str As String
str = "String test "
MsgBox("The value holding str is : " & str)
End Sub
End Class
When you execute this programme , you will get "true" in the first message box and , 100 in the second message box and "String Test" in the last message box.