Data types in VB.net
By: Steven Holzner in VB.net Tutorials on 2008-11-25
It's time to create a new variable-but what type should you use? For that matter, exactly what kinds of variable types are there and what do they do? Even if you remember what types there are, you probably won't remember the range of possible values a particular variable type allows.
There is a wide range of data types. The Visual Basic variable types appear in Table below for reference, making selecting the right type a little easier. Note that the Single and Double types handle floating point values, which the Integer types (such as Short, Integer, and Long) do not; these names are short for single precision floating point and double precision floating point. You might also notice that there are some new types in VB .NET that weren't in VB6, like Char, and that some other types, like Currency or Variant, are gone. Note in particular the Boolean data type, which takes values like True or False only-also called logical values.
Type |
Storage size |
Value range |
---|---|---|
Boolean |
2 bytes |
True or False |
Byte |
1 byte |
0 to 255 (unsigned) |
Char |
2 bytes |
0 to 65535 (unsigned) |
Date |
8 bytes |
January 1, 0001 to December 31, 9999 |
Decimal |
16 bytes |
+/-79,228,162,514,264,337,593,543,950,335 with no decimal point; 7.92281625142643 37593543950335 with 28 places to the right of the decimal; smallest non-zero number is 0.00000 00000000000000000000001 |
Double |
8 bytes |
-1.79769313486231E+308 to -4.94065645841247E-324 for negative values; 4.94065645841247E-324 to 1.79769313486231E+308 for positive values |
Integer |
4 bytes |
-2,147,483,648 to 2,147,483,647 |
Long |
8 bytes |
-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Object |
4 bytes |
Any type can be stored in a variable of type Object |
Short |
2 bytes |
-32,768 to 32,767 |
Single |
4 bytes |
-3.402823E to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E for positive values |
String |
Depends on implementing platform |
0 to approximately 2 billion Unicode characters |
User-Defined Type (structure) |
Sum of the sizes of its members. Each member of the structure has a range determined by its data type and independent of the ranges of the other members |
Add Comment
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
- Your name, rating, website address, town, country, state and comment will be publicly displayed if entered.
- Aside from the data entered into these form fields, other stored data about your comment will include:
- Your IP address (not displayed)
- The time/date of your submission (displayed)
- Your email address will not be shared. It is collected for only two reasons:
- Administrative purposes, should a need to contact you arise.
- To inform you of new comments, should you subscribe to receive notifications.
- A cookie may be set on your computer. This is used to remember your inputs. It will expire by itself.
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
- Although the administrator will attempt to moderate comments, it is impossible for every comment to have been moderated at any given time.
- You acknowledge that all comments express the views and opinions of the original author and not those of the administrator.
- You agree not to post any material which is knowingly false, obscene, hateful, threatening, harassing or invasive of a person's privacy.
- The administrator has the right to edit, move or remove any comment for any reason and without notice.
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
- Data Science
- Android
- React Native
- AJAX
- ASP.net
- C
- C++
- C#
- Cocoa
- Cloud Computing
- HTML5
- Java
- Javascript
- JSF
- JSP
- J2ME
- Java Beans
- EJB
- JDBC
- Linux
- Mac OS X
- iPhone
- MySQL
- Office 365
- Perl
- PHP
- Python
- Ruby
- VB.net
- Hibernate
- Struts
- SAP
- Trends
- Tech Reviews
- WebServices
- XML
- Certification
- Interview
categories
Related Tutorials
Changes in Controls from VB6 to VB.net
Unstructured Exception Handling in VB.net
Structured Exception Handling in VB.net
Creating Sub Procedures in VB.net
Passing a Variable Number of Arguments to Procedures in VB.net
Specifying Optional Arguments with default values in Procedures in VB.net
Preserving a Variable's Values between Procedure Calls in VB.net
Throwing an Exception in VB.net
Comments