Lecture 3 Labwork Part 1
Lecture 3 Labwork Part 1
A Data Type refers to which type of data or value is assigning to a variable or function
so that a variable can hold a defined data type value. For example, when we declare a
variable, we have to tell the compiler what type of data or value is allocated to different
kinds of variables to hold different amounts of space in computer memory.
Syntax:
VariableName: It defines the name of the variable that you assign to store values.
DataType: It represents the name of the data type that you assign to a variable.
1|Page
Decimal 16 bytes Range from 0 to +/-
79,228,162,514,264,337,593,543,950,335
(+/-7.9…E+28) without any decimal point;
And 0 to +/-7.92281625142264337593543950335
with 28 position to the right of the decimal
Object Object size based on the It can store any type of data defined in a variable
platform such as 4 bytes of type Object
in 32-bit and 8 bytes in
64-bit platform
2|Page
ULong 8 bytes The range of ULong start from 0 to
18,446,744,073,709,551,615 (1.8…E + 19)
(unsigned)
User- A user-defined data type Each member of the structure has its own data
Defined depends on the type and limits independent of the other
(structure) implementing platform members' ranges.
Data_type.vb
1. Module Data_type
2. Sub Main()
3. ' defining the Data Type to the variables
4. Dim b As Byte = 1
5. Dim num As Integer = 5
6. Dim si As Single
7. Dim db As Double
8. Dim get_date As Date
9. Dim c As Char
10. Dim str As String
11.
12. b=1
13. num = 20
14. si = 0.12
15. db = 2131.787
16. get_date = Today
17. c = "A"
18. str = "Hello Friends..."
19.
20. Console.WriteLine("Welcome to the VB.NET Data Types")
21. Console.WriteLine("Byte is: {0}", b)
3|Page
22. Console.WriteLine("Integer number is: {0}", num)
23. Console.WriteLine("Single data type is: {0}", si)
24. Console.WriteLine("Double data type is: {0}", db)
25. Console.WriteLine("Today is: {0}", get_date)
26. Console.WriteLine("Character is: {0}", b)
27. Console.WriteLine("String message is: {0}", str)
28. Console.ReadKey()
29. End Sub
30. End Module
Output:
4|Page
12. CSng(expression): It is used to convert an expression into a Single data type.
13. CStr(expression): It is used to convert an expression into a String data type.
14. CUInt(expression): It is used to convert an expression to a UInt data type.
15. CULng(expression): It is used to convert an expression to a ULng data type.
16. CUShort(expression): It is used to convert an expression into a UShort data type.
DB_Conversion.vb
1. Option Strict On
2. Module DB_Conversion
3. Sub Main()
4. 'defining the Data type conversion
5. Dim dblData As Double
6. dblData = 5.78
7. Dim A, B As Char
8. Dim bool As Boolean = True
9. Dim x, Z, B_int As Integer
10. A = "A"
11. B = "B"
12. B_int = AscW(B)
13.
14. Console.WriteLine(" Ascii value of B is {0}", B_int)
15.
16. x=1
17. Z = AscW(A)
18. Z=Z+x
19. Console.WriteLine("String to integer {0}", Z)
20. Console.WriteLine("Boolean value is : {0}", CStr(bool))
21. Dim num, intData As Integer
22.
23. num = CInt(dblData)
5|Page
24. intData = CType(dblData, Integer)
25. Console.WriteLine(" Explicit conversion of Data type " & Str(intData))
26. Console.WriteLine(" Value of Double is: {0}", dblData)
27. Console.WriteLine("Double to Integer: {0}", num)
28. Console.ReadKey()
29. End Sub
30. End Module
Output:
Ascii value of B is 66
String to integer 66
Boolean value is: True
Explicit conversion of Data type 6
Value of Double is: 5.78
Double to Integer: 6
Note: For data type conversion, the VB.NET provides Option Strict On that allows us
to convert one data type to another. Some data types in VB.NET reject the conversion
because of "Option Strict On". Remember that while performing conversion, turn off
the Option Strict mode.
6|Page