Вы находитесь на странице: 1из 4

There are two types of data type in VB.

NET
Primitive (Predefine) Non-Primitive (User Defined) Primitive data types are further divided as: Byte, SByte, Short, UShort,Integer,UInteger, Long,ULong, Single, Double,Decimal,Char,Boolean,Date,String, Object Non-primitive data types are further divided as: Class,Structure,Enum,Interface,Delegate,Array The built-in value types VB Bytes .NET type Description Keyword Byte SByte Short UShort Integer UInteger Long ULong Single Double Decimal 1 1 2 2 4 5 8 8 4 8 16 Byte SByte Int16 UInt16 Int32 UInt32 Int64 UInt64 Single Double Decimal 0-255 -128 to 127 -32,768 to +32,767 0 to 65535 -2,147,483,648 to + 2,147,483,647 0 to 4,294,967,295 -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 0 to +18,446,744,073,709,551,615 A non integer number with approximately 7 significant digits A non integer number with approximately 14 significant digits A non integer number with approximately 28 significant digits (integer and fraction) that can represent values up to 79,228 X 1024 A single Unicode character

Char

Char

Boolean 1 Boolean A True or False value Common .NET structures that define value types Structure VB Keyword What the value type holds Byte Int16 Int32 Int64 Single Double Decimal Byte Short Integer Long Single Double Decimal An 8-bit unsigned integer An 16-bit signed integer An 32-bit signed integer An 64-bit signed integer A single-precision floating-point number A double-precision floating-point number A 96-bit decimal value

Boolean

Boolean

True or False value

Char Character A single character Common .NET classes that define reference types Class Name VB Keyword What the reference type holds String String A reference to a String object Object Object A reference to any type of object Variable Variable are data types whose value can change during the program execution. Variable are involved in processing. Example: Dim age As Integer = 23 Constant Constant are data types whose value doesn't change during program executions Constant are not involved in processing. Example: Const pi As Double = 3.1415 In case of constant the declaration and value assigning has to be at the same time. Snippet code in VB.NET on variable and constant Module Module1 Sub Main() Dim age As Integer = 34 Const pi As Double = 3.1415 Console.WriteLine("Age is: " & age) Console.WriteLine("Pi value is: " & pi) Console.ReadLine() End Sub End Module In .NET Microsoft has divided data types in two parts: Value Type (Fixed in size) Reference Type (Not fixed in size) In application context, value types are stored in stack but reference types are stored in managed heap. Value Type Value types are fixed in size. Value types are made in system stack. Actual values of data are stored in stack. If you assign a value of a variable to another it will create two copies. All primitive data type except string and object are example of value types. Object is a super type. It can store any type and any size of data. Object is called super type because it helps in inheritance. struct and enum are value type. Note: Stack is an operation entity (LIFO) i.e. it is fixed in size. Reference Type

Reference types are not fixed in size. They are maintained in system managed heap but it also uses stack to store reference of heap. Two primitive types (string and object) and non-primitive data types (class, interface & delegate) are examples of reference type. CLR manages heap (large memory area). Heap address is accessed from stack. In reference type reference is used for processing using both managed heap and stack (operational entity).

Data Type Conversion, File Extensions


Converting between Data types In Visual Basic, data can be converted in two ways: implicitly, which means the conversion is performed automatically, and explicitly, which means you must perform the conversion. Implict Conversions Let's understand implicit conversions in code. The example below declares two variable, one of type double and the other integer. The double data type is assigned a value and is converted to integer type. When you run the code the result displayed is an integer value, in this case the value displayed is 132 instead of 132.31223. Imports System.Console Module Module1 Sub Main() Dim d=132.31223 as Double Dim i as Integer i=d WriteLine("Integer value is" & i) End Sub End Module Explicit Conversions When types cannot be implicitly converted you should convert them explicitly. This conversion is also called as cast. Explicit conversions are accomplished using CType function. CType function for conversion If we are not sure of the name of a particular conversion function then we can use the CType function. The above example with a CType function looks like this: Imports System.Console Module Module1 Sub Main() Dim d As Double d = 132.31223 Dim i As Integer i = CType(d, i) 'two arguments, type we are converting from, to type desired WriteLine("Integer value is" & i) End Sub End Module Below is the list of conversion functions which we can use in VB .NET. CBool - use this function to convert to Bool data type CByte - use this function to convert to Byte data type CChar - use this function to convert to Char data type CDate - use this function to convert to Date type CDbl - use this function to convert to Double data type CDec - use this function to convert to Decimal data type CInt - use this function to convert to Integer data type CLng - use this function to convert to Long data type CObj - use this function to convert to Object type

CShort - use this function to convert to Short data type CSng - use this function to convert to Single data type CString - use this function to convert to String data type Attributes Attributes are those that lets us specify information about the items we are using in VB .NET. Attributes are enclosed in angle brackets(< >) and are used when VB .NET needs to know more beyond the standard syntax. File Extensions in VB .NET The files and their extensions which are created as part of the Windows Application Project and their meaning are summarized below: .vbproj->A Visual Basic project Form1.vb->A form's code AssemblyInfo.VB->Information about an assembly, includes version information .vbproj.user->Stores project user options .sln->Solution file which stores solution's configuration .suo-> Stores Solution user options Form1.resx.NET->XML based resource template bin directory->Directory for binary executables obj directory->Directory for debugging binaries Language Terminology Briefly on some terminology when working with the language: Module: Used to hold code Variable: A named memory location of a specific data type used to hold some value Procedure: A callable series of statements which may or may not return a value Sub-Procedure: A procedure with no return value Function: A procedure with return value Methods: A procedure built into the class Constructor: Special method used to initialize and customize the object. It has the same name as the class Class: An OOP class which contains data and code Object: An instance of a class Arrays: Programming constructs that lets us access data by numeric index Attributes: They are the items that specify information about other items being used in VB. NET

Вам также может понравиться