Academic Tutorials



English | French | Portugese | German | Italian
Google

Home Source Codes E-Books Downloads Contact Us About Us

VB.NET
Introduction to VB.NET
Visual Basic Scripts
Variables and Data Types
Arrays and Collections
Arithmetic and String Operations
Relational and Logical Operations
Math and String Functions
Date and Time Functions
Display Formats
Subprograms
Functions
The If Statement
The If...Else Statement
The Else...If Statement
The Select...Case Statement
The For...Next Statement
The For Each...Next Statement
The While...End While Statement
The Do...Loop Statement

HTML Tutorials
HTML Tutorial
XHTML Tutorial
CSS Tutorial
TCP/IP Tutorial
XML Tutorials
XML Tutorial
XSL Tutorial
XSLT Tutorial
DTD Tutorial
Schema Tutorial
XForms Tutorial
XSL-FO Tutorial
XML DOM Tutorial
XLink Tutorial
XQuery Tutorial
XPath Tutorial
XPointer Tutorial
RDF Tutorial
SOAP Tutorial
WSDL Tutorial
RSS Tutorial
WAP Tutorial
Web Services Tutorial
Browser Scripting
JavaScript Tutorial
VBScript Tutorial
AJAX Tutorial
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PHP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
.NET (dotnet)
Microsoft.Net
XML Web Services
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills


Variables and Data Types
Previous Next


  • Computer programs are processors of data and therefore, they need of way of representing various types of data -- numbers, alphabetic characters, special characters, and the like -- inside the computer.


  • Also,during processing programs need a way to hold onto -- to store -- these data inside computer memory.


  • Declaring Variables

    Variables are named storage areas inside computer memory where a program places data during processing. A program sets aside these storage areas by declaring variables, that is, by assigning them a name and indicating what types of data will occupy these areas during processing.

    Within a Visual Basic program, variables are declared using the Dim statement whose general format is shown below.

    Dim variable As type
    where type is one of the data types permissible in Visual Basic and variable is a programmer-supplied name for the storage area.


    Naming Variables

    Programmer-supplied variable names are also referred to as identifiers, and they must conform to Visual Basic naming conventionsand a variable name must

    • Be composed only of alphabetic,underscore, and numeric characters.
    • Begin with an numeric or alphabetic character, or the underscore (_) character.
    • Not contain any embedded blank spaces.
    • Not be the same as a Visual Basic keyword, words the comprise of the Visual Basic language itself.

    Variable names are not case sensitive, so the name expressed in upper-case characters refers to the same storage area as a name expressed in lower-case characters and however, for programming consistency, and to avoid unnecessary errors, it is best to express a variable as it is originally declared. Thus, valid variable names include X, My_Variable, MyVariable, My_Data_Variable, and other names using meaningful and simple identifiers.




    Data Types

    When declaring a variable an indication can be given about what type of data will be stored and there are many data types permissible under Visual Basic.In computer processing,the following are common for declaring the usual types of data involved:

    • Short. A non-decimal (whole) number with a value in the range of the -32,768 to +32,767.
       
    • Integer. A non-decimal (whole) number with a value in the range of the -2,147,483,648 to +2,147,483,647.
       
    • Long. A non-decimal (whole) number with a value in the range of the -9,223,372,036,854,775,808 to +9,223,372,036,854,775,807.
       
    • Single. A floating-point (decimal) positive or negative number with a value in the range of up to the 3.402823E38 (scientific notation).
       
    • Double A floating-point (decimal) positive or negative number with a value in the range of up to the 1.79769313486232E308.
       
    • Decimal. A decimal number with a value in the range of up to +79,228,162,514,264,337,593,950,335. without decimal precision and up to the +7.9228162514264337593543950335 with 28 places of decimal precision.
       
    • String. Any number of special, numerical,alphabetic and special characters.
       
    • Date Dates in the range between January 1, 0001 to December 31, 9999 and times in the range between 0:00:00 to the 23:59:59.
       
    • Boolean. The value of True or False.

       

    Variables, then, are declared by assigning a name and a data type and the following are examples of valid variable declarations that can be used to store data of the identified types.

    Dim My_Counter As Integer
    Dim My_Salary As Decimal
    Dim My_Great-Big-Number As Double
    Dim My_Name As String
    Dim My_Birthday As Date
    Dim My_Current_Time As Date
    Dim My_Decision As Boolean



    Assigning Values to Variables

    With the Visual Basic assignment statement,variables are assigned values whose general format is shown below.

    Variable declarations simply set aside memory storage areas as temporary containers of data -- temporary because they are no longer accessible once the program ends and during processing, of course, these variables are occupied by data values.

    Data for processing can come from many different sources and they can come from outside the program -- from external files and databases; they can come from inside the program by explicitly setting a value for a variable or by storing processing results of manipulating other variables. In any case, variables take on values by assigning values to them.

    variable = value



    Assigning Expressions to Variables

    Some type of arithmetic, string, or date manipulation operation takes place with the "answer" stored in the variable.The most common scenario is that the results of processing are assigned to a variable. Although these types of operations are discussed later, you should be able to understand the principles involved in the following assignment statements.

    Dim The_Answer As Decimal
    Dim Var_A As Decimal = 2.5
    Dim Var_B As Decimal = 3.5
    The_Answer = 5 * (Var_A + Var_B)



    The Variant Data Type

    If variable types are not explicitly declared -- using As Integer, As Decimal, As String, etc. -- then values assigned to the variable are stored as a Variant data type and any type of data can be stored in the variable and any type of operation can be performed on it. It is a general-purpose data type that provides flexibility in storing different types of data in a single variable. It can be assigned a numeric value that is immediately replaced by a string value.

    Although it does offer some programming flexibility, there are minor inefficiences associated with converting different data types for representation in the same storage area and for this reason only it is best always to declare specific data types for specific variables. This practice of using strong typing of variables leads to more efficient programming and reduction in errors from inadvertently storing the wrong kinds of data in the wrong variables.




    Type Conversions

    Values of one data type can be converted to another data type using type conversion. This operation is called casting from one type to another and casting requires calling a conversion function to switch a data type. The resulting cast must be assigned to a variable of the cast type.




    Share And Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
    • blinkbits
    • BlinkList
    • blogmarks
    • co.mments
    • connotea
    • del.icio.us
    • De.lirio.us
    • digg
    • Fark
    • feedmelinks
    • Furl
    • LinkaGoGo
    • Ma.gnolia
    • NewsVine
    • Netvouz
    • RawSugar
    • Reddit
    • scuttle
    • Shadows
    • Simpy
    • Smarking
    • Spurl
    • TailRank
    • Wists
    • YahooMyWeb

    Previous Next

    Keywords: Variables and Data Types in VB.NET, vb net data, mysql variables, perl variables, asp variables, php variables, statistics variables, regression data, array variables, regression variables, function variables, javascript data, statistics data, method variables, data analysis, asp data


    HTML Quizes
    HTML Quiz
    XHTML Quiz
    CSS Quiz
    TCP/IP Quiz
    XML Quizes
    XML Quiz
    XSL Quiz
    XSLT Quiz
    DTD Quiz
    Schema Quiz
    XForms Quiz
    XSL-FO Quiz
    XML DOM Quiz
    XLink Quiz
    XQuery Quiz
    XPath Quiz
    XPointer Quiz
    RDF Quiz
    SOAP Quiz
    WSDL Quiz
    RSS Quiz
    WAP Quiz
    Web Services Quiz
    Browser Scripting Quizes
    JavaScript Quiz
    VBScript Quiz
    AJAX Quiz
    DHTML Quiz
    HTML DOM Quiz
    WMLScript Quiz
    E4X Quiz
    Server Scripting Quizes
    ASP Quiz
    PHP Quiz
    PERL Quiz
    SQL Quiz
    ADO Quiz
    .NET (dotnet) Quizes
    Microsoft.Net Quiz
    XML Web Services Quiz
    ASP.Net Quiz
    .Net Mobile Quiz
    C# : C Sharp Quiz
    ADO.NET Quiz
    VB.NET Quiz
    Multimedia Quizes
    SVG Quiz
    Flash Quiz
    Media Quiz
    SMIL Quiz
    Web Building  Quizes
    Web Browsers Quiz
    Web Hosting Quiz
    W3C Quiz
    Web Building Quiz
    Web Quality Quiz
    Web Semantic Quiz
    Web Careers Quiz
    Java Quizes
    Java Quiz
    JSP Quiz
    Servlets Quiz
    Struts Quiz
    EJB Quiz
    JMS Quiz
    JMX Quiz
    Programming Langauges Quizes
    C Quiz
    C++ Quiz
    Visual Basic Quiz
    Data Structures Using C Quiz
    Soft Skills Quizes
    Communication Skills Quiz
    Time Management Quiz
    Project Management Quiz
    Team Work Quiz
    Leadership Skills Quiz
    Corporate Communication Quiz
    Negotiation Skills Quiz

    Privacy Policy
    Copyright © 2003-2008 Vyom Technosoft Pvt. Ltd., All Rights Reserved.