Academic Tutorials



English | French | Portugese | German | Italian
Home Advertise Payments Recommended Websites Interview Questions FAQs
News Source Codes E-Books Downloads Jobs Web Hosting
Chats

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
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
CSS 1.0
CSS 2.0
HLML
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
DHTML Tutorial
HTML DOM Tutorial
WMLScript Tutorial
E4X Tutorial
Server Scripting
ASP Tutorial
PERL Tutorial
SQL Tutorial
ADO Tutorial
CVS
Python
Apple Script
PL/SQL Tutorial
SQL Server
PHP
.NET (dotnet)
Microsoft.Net
ASP.Net
.Net Mobile
C# : C Sharp
ADO.NET
VB.NET
VC++
Multimedia
SVG Tutorial
Flash Tutorial
Media Tutorial
SMIL Tutorial
Photoshop Tutorial
Gimp Tutorial
Matlab
Gnuplot Programming
GIF Animation Tutorial
Scientific Visualization Tutorial
Graphics
Web Building
Web Browsers
Web Hosting
W3C Tutorial
Web Building
Web Quality
Web Semantic
Web Careers
Weblogic Tutorial
SEO
Web Site Hosting
Domain Name
Java Tutorials
Java Tutorial
JSP Tutorial
Servlets Tutorial
Struts Tutorial
EJB Tutorial
JMS Tutorial
JMX Tutorial
Eclipse
J2ME
JBOSS
Programming Langauges
C Tutorial
C++ Tutorial
Visual Basic Tutorial
Data Structures Using C
Cobol
Assembly Language
Mainframe
Forth Programming
Lisp Programming
Pascal
Delphi
Fortran
OOPs
Data Warehousing
CGI Programming
Emacs Tutorial
Gnome
ILU
Soft Skills
Communication Skills
Time Management
Project Management
Team Work
Leadership Skills
Corporate Communication
Negotiation Skills
Database Tutorials
Oracle
MySQL
Operating System
BSD
Symbian
Unix
Internet
IP-Masquerading
IPC
MIDI
Software Testing
Testing
Firewalls
SAP Module
ERP
ABAP
Business Warehousing
SAP Basis
Material Management
Sales & Distribution
Human Resource
Netweaver
Customer Relationship Management
Production and Planning
Networking Programming
Corba Tutorial
Networking Tutorial
Microsoft Office
Microsoft Word
Microsoft Outlook
Microsoft PowerPoint
Microsoft Publisher
Microsoft Excel
Microsoft Front Page
Microsoft InfoPath
Microsoft Access
Accounting
Financial Accounting
Managerial Accounting
Network Sites


Variables and Data Types

Previoushome 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.

  • A D V E R T I S E M E N T
  • 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.



    Be the first one to comment on this page.




      VB.NET eBooks
    More Links » »
     
     VB.NET FAQs
    More Links » »
     
     VB.NET Interview Questions
    More Links » »
     
     VB.NET Articles
    More Links » »
     
     VB.NET News
    More Links » »
     
     VB.NET Jobs
    More Links » »

    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

    Previoushome 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 Quizzes
    HTML Quiz
    XHTML Quiz
    CSS Quiz
    TCP/IP Quiz
    CSS 1.0 Quiz
    CSS 2.0 Quiz
    HLML Quiz
    XML Quizzes
    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 Quizzes
    JavaScript Quiz
    VBScript Quiz
    DHTML Quiz
    HTML DOM Quiz
    WMLScript Quiz
    E4X Quiz
    Server Scripting Quizzes
    ASP Quiz
    PERL Quiz
    SQL Quiz
    ADO Quiz
    CVS Quiz
    Python Quiz
    Apple Script Quiz
    PL/SQL Quiz
    SQL Server Quiz
    PHP Quiz
    .NET (dotnet) Quizzes
    Microsoft.Net Quiz
    ASP.Net Quiz
    .Net Mobile Quiz
    C# : C Sharp Quiz
    ADO.NET Quiz
    VB.NET Quiz
    VC++ Quiz
    Multimedia Quizzes
    SVG Quiz
    Flash Quiz
    Media Quiz
    SMIL Quiz
    Photoshop Quiz
    Gimp Quiz
    Matlab Quiz
    Gnuplot Programming Quiz
    GIF Animation Quiz
    Scientific Visualization Quiz
    Graphics Quiz
    Web Building Quizzes
    Web Browsers Quiz
    Web Hosting Quiz
    W3C Quiz
    Web Building Quiz
    Web Quality Quiz
    Web Semantic Quiz
    Web Careers Quiz
    Weblogic Quiz
    SEO Quiz
    Web Site Hosting Quiz
    Domain Name Quiz
    Java Quizzes
    Java Quiz
    JSP Quiz
    Servlets Quiz
    Struts Quiz
    EJB Quiz
    JMS Quiz
    JMX Quiz
    Eclipse Quiz
    J2ME Quiz
    JBOSS Quiz
    Programming Langauges Quizzes
    C Quiz
    C++ Quiz
    Visual Basic Quiz
    Data Structures Using C Quiz
    Cobol Quiz
    Assembly Language Quiz
    Mainframe Quiz
    Forth Programming Quiz
    Lisp Programming Quiz
    Pascal Quiz
    Delphi Quiz
    Fortran Quiz
    OOPs Quiz
    Data Warehousing Quiz
    CGI Programming Quiz
    Emacs Quiz
    Gnome Quiz
    ILU Quiz
    Soft Skills Quizzes
    Communication Skills Quiz
    Time Management Quiz
    Project Management Quiz
    Team Work Quiz
    Leadership Skills Quiz
    Corporate Communication Quiz
    Negotiation Skills Quiz
    Database Quizzes
    Oracle Quiz
    MySQL Quiz
    Operating System Quizzes
    BSD Quiz
    Symbian Quiz
    Unix Quiz
    Internet Quiz
    IP-Masquerading Quiz
    IPC Quiz
    MIDI Quiz
    Software Testing Quizzes
    Testing Quiz
    Firewalls Quiz
    SAP Module Quizzes
    ERP Quiz
    ABAP Quiz
    Business Warehousing Quiz
    SAP Basis Quiz
    Material Management Quiz
    Sales & Distribution Quiz
    Human Resource Quiz
    Netweaver Quiz
    Customer Relationship Management Quiz
    Production and Planning Quiz
    Networking Programming Quizzes
    Corba Quiz
    Networking Quiz
    Microsoft Office Quizzes
    Microsoft Word Quiz
    Microsoft Outlook Quiz
    Microsoft PowerPoint Quiz
    Microsoft Publisher Quiz
    Microsoft Excel Quiz
    Microsoft Front Page Quiz
    Microsoft InfoPath Quiz
    Microsoft Access Quiz
    Accounting Quizzes
    Financial Accounting Quiz
    Managerial Accounting Quiz
    Testimonials | Contact Us | Link to Us | Site Map
    Copyright ? 2008. Academic Tutorials.com. All rights reserved Privacy Policies | About Us
    Our Portals : Academic Tutorials | Best eBooksworld | Beyond Stats | City Details | Interview Questions | Discussions World | Excellent Mobiles | Free Bangalore | Give Me The Code | Gog Logo | Indian Free Ads | Jobs Assist | New Interview Questions | One Stop FAQs | One Stop GATE | One Stop GRE | One Stop IAS | One Stop MBA | One Stop SAP | One Stop Testing | Webhosting in India | Dedicated Server in India | Sirf Dosti | Source Codes World | Tasty Food | Tech Archive | Testing Interview Questions | Tests World | The Galz | Top Masala | Vyom | Vyom eBooks | Vyom International | Vyom Links | Vyoms | Vyom World | Important Websites
    Copyright ? 2003-2024 Vyom Technosoft Pvt. Ltd., All Rights Reserved.