VB.net Datatypes

download VB.net Datatypes

of 7

Transcript of VB.net Datatypes

  • 8/8/2019 VB.net Datatypes

    1/7

    VB.NET Brief Introduction.

    Visual Basic .NET (VB.NET) is an object-oriented computer programming language

    that can be viewed as an evolution of Microsoft's Visual Basic (VB) which is

    generally implemented on the Microsoft .NET Framework.

    .NET Framework what it is?

    (Features: What the .NET Framework is supposed to do. )

    The .NET Framework is an integral Windows component that supports building and

    running the next generation of applications and XML Web services.

    To provide a consistent object-oriented programming environment whetherobject code is stored and executed locally, executed locally but Internet-distributed, or executed remotely.

    To provide a code-execution environment that minimizes softwaredeployment and versioning conflicts.

    To provide a code-execution environment that promotes safe execution ofcode, including code created by an unknown or semi-trusted third party.

    To provide a code-execution environment that eliminates the performanceproblems of scripted or interpreted environments.

    To make the developer experience consistent across widely varying types ofapplications, such as Windows-based applications and Web-basedapplications.

    To build all communication on industry standards to ensure that code basedon the .NET Framework can integrate with any other code.

    (The Parts of .NET Framework)

    The .NET Framework has two main components: the common language runtime

    and the .NET Framework class library.

    The common language runtime is the foundation of the .NET Framework. You can

    think of the runtime as an agent that manages code at execution time, providing

    core services such as memory management, thread management, and remoting,

    while also enforcing strict type safety and other forms of code accuracy that

    promote security and robustness.

    The other main component of the .NET Framework is the Class Library which is a

    comprehensive, object-oriented collection of reusable types that you can use to

    develop applications ranging from traditional command-line or graphical user

    interface (GUI) applications to applications based on the latest innovations provided

    by ASP.NET, such as Web Forms and XML Web services.

  • 8/8/2019 VB.net Datatypes

    2/7

  • 8/8/2019 VB.net Datatypes

    3/7

    Field Information:

    Visual Basic Type: the Common name of the Datatype

    CLR Type Structure: The Class library that contains the Datatype

    Nominal Storage Allocation: Specifies the amount of bytes allocated in memory.

    Value Range: The Value range within which it is safe to use these data types, outside which the roundingeffects or spurious value generation will occur.

    Visual Basictype

    Common language runtimetype structure

    Nominal storageallocation

    Value range

    Boolean System.Boolean 2 bytes True or False.

    Byte System.Byte 1 byte 0 through 255 (unsigned).

    Char System.Char 2 bytes 0 through 65535 (unsigned).

    Date System.DateTime 8 bytes 0:00:00 on January 1, 0001 through 11:59:59 PM on

    December 31, 9999.

    Decimal System.Decimal 16 bytes 0 through +/-

    79,228,162,514,264,337,593,543,950,335 with no

    decimal point;

    0 through +/-7.9228162514264337593543950335

    with 28 places to the right of the decimal; smallest

    nonzero number is

    +/-0.0000000000000000000000000001 (+/-1E-28).

    Double(double-

    precision

    floating-point)

    System.Double 8 bytes -1.79769313486231570E+308 through-4.94065645841246544E-324 for negative values;

    4.94065645841246544E-324 through

    1.79769313486231570E+308 for positive values.

    Integer System.Int32 4 bytes -2,147,483,648 through 2,147,483,647.

    Long

    (long integer)

    System.Int64 8 bytes -9,223,372,036,854,775,808 through

    9,223,372,036,854,775,807.

    Object System.Object (class) 4 bytes Any type can be stored in a variable of type Object.

    Short System.Int16 2 bytes -32,768 through 32,767.

    Single

    (single-precision

    floating-point)

    System.Single 4 bytes -3.4028235E+38 through -1.401298E-45 for negative

    values; 1.401298E-45 through 3.4028235E+38 forpositive values.

    String

    (variable-

    length)

    System.String (class) Depends on

    implementing

    platform

    0 to approximately 2 billion Unicode characters.

    User-

    Defined

    (inherits from

    System.ValueType)

    Depends on

    implementing

    Each member of the structure has a range

    determined by its data type and independent of the

  • 8/8/2019 VB.net Datatypes

    4/7

    Type

    (structure)

    platform ranges of the other members.

    Simplifying the above table:

    1. Numerical Data Types

    a. Whole Numbers

    i. Byte

    ii. Short

    iii. Integer

    iv. Decimal

    v. Long

    b. Real numbers

    i. Single (float)

    ii. Double

    2. Character Data Types

    a. Only One Character

    i. Char

    b. Many Character

    i. String

    3. Binary Data Types

    a. Byte

    4. Date

    a. Contains Date and Time both at the same time.

    5. Boolean

    a. Contains the Yes or No information Yes is represented as a 1 and No as a 0

    How to Declare a Variable in VB.NET

    Dim As

  • 8/8/2019 VB.net Datatypes

    5/7

    ex: Dim i As Integer

    ex: Dim Age As Integer

    ex: Dim TDate as Date

    Ex: Dim I, J, K As Integer ' All three are Integervariables.

    Ex: Dim L, M As Long, X, Y As Single ' L and M are Long, X and

    Y are Single.

    Variable Scope or Lifetime

    A local variable is one that is declared within a procedure. A module variable is declared at

    module level, inside the module but not within any procedure internal to that module.

    Thescope of a variable is the set of all code that can refer to it without qualifying its name.

    A variable's scope is determined by where the variable is declared. Code located in a given

    region can use the variables defined in that region without having to qualify their names.

    When declaring scope, the following rules apply:

    The scope of a module variable is the entire namespace in which the module

    is defined.

    The scope of a shared or instance variable is the structure or class in which it

    is declared.

    The scope of a local variable is the procedure in which it is declared.

    However, if you declare a local variable within a block, its scope is that block

    only. A block is a set of statements terminated by an End, Else, Loop, or Next

    statement; for example, a For...Next or If...Then...Else...End If construction.

    Declaring Accessibility

    A variable's accessibility is determined by which keyword or keywords Dim, Public,

    Protected, Friend, Protected Friend, or Private you use in the declaration statement.

    You can declare a module, structure, class, or instance variable with any of these keywords.

    Within a procedure, only the Dim keyword is allowed, and the accessibility is always

    private.

    Rules for Variable Name.

    1.) Name must Begine with an AlphabetOnly

    2.) Name must only contain AlphaNumeric Characters and or Undescore.

  • 8/8/2019 VB.net Datatypes

    6/7

    3.) Name must Be Meaningful, Ex: age, Rollnum, Price etc. Meaningless names as abc, s, cv

    etc must be avoided.

    4.) Name cannot be a VB.NET Keyword.

    5.) Same Named Variables Cannot be used in Same Module.

    6.) Variable Name must be limited to 32 Characters (Although more are permitted )

    7.) VB.NET is not Case sensitive so variable "age", "Age","AGE" will be considered the

    same which is not in the case of Visual C++ or C# where each variable will considered to be

    a different variable.

  • 8/8/2019 VB.net Datatypes

    7/7

    asddadasasd