Sideway from Sideway
Draft for Information Only


VB.NET Data Types
  Boolean Data Type
  Type Conversions
  Programming Tips
  See also
  Char Data Type
  Unicode Characters
  Type Conversions
  Programming Tips
  See also
  Date Data Type
  Format Requirements
  Hour Format
  Date and Time Defaults
  Type Conversions
  Programming Tips
  See also
  Decimal Data Type
  Programming Tips
  See also

VB.NET Data Types

The supporting VB.NET data types can be divided into

  • Specific forms: String, Object, User-Defined
  • Typical forms: Boolean, Char(2), Date(8), Decimal(16)
  • Unsigned numerics: Byte (1), UShort(2), UInteger(4), ULong(8)
  • Singed numerics:  SByte(1), Short(2), Integer(4), Long(8)
  • Numeric ranges: Single(4), Double(8)

Boolean Data Type

Holds values that can be only True or False. The keywords True and False correspond to the two states of Boolean variables.


Use the Boolean Data Type (Visual Basic) to contain two-state values such as true/false, yes/no, or on/off.

The default value of Boolean is False.

Boolean values are not stored as numbers, and the stored values are not intended to be equivalent to numbers. You should never write code that relies on equivalent numeric values for True and False. Whenever possible, you should restrict usage of Boolean variables to the logical values for which they are designed.

Type Conversions

When Visual Basic converts numeric data type values to Boolean, 0 becomes False and all other values become True. When Visual Basic converts Boolean values to numeric types, False becomes 0 and True becomes -1.

When you convert between Boolean values and numeric data types, keep in mind that the .NET Framework conversion methods do not always produce the same results as the Visual Basic conversion keywords. This is because the Visual Basic conversion retains behavior compatible with previous versions. For more information, see "Boolean Type Does Not Convert to Numeric Type Accurately" in Troubleshooting Data Types.

Programming Tips

  • Negative Numbers. Boolean is not a numeric type and cannot represent a negative value. In any case, you should not use Boolean to hold numeric values.

  • Type Characters. Boolean has no literal type character or identifier type character.

  • Framework Type. The corresponding type in the .NET Framework is the System.Boolean structure.

See also

Char Data Type

Holds unsigned 16-bit (2-byte) code points ranging in value from 0 through 65535. Each code point, or character code, represents a single Unicode character.


Use the Char data type when you need to hold only a single character and do not need the overhead of String. In some cases you can use Char(), an array of Char elements, to hold multiple characters.

The default value of Char is the character with a code point of 0.

Unicode Characters

The first 128 code points (0–127) of Unicode correspond to the letters and symbols on a standard U.S. keyboard. These first 128 code points are the same as those the ASCII character set defines. The second 128 code points (128–255) represent special characters, such as Latin-based alphabet letters, accents, currency symbols, and fractions. Unicode uses the remaining code points (256-65535) for a wide variety of symbols, including worldwide textual characters, diacritics, and mathematical and technical symbols.

You can use methods like IsDigit and IsPunctuation on a Char variable to determine its Unicode classification.

Type Conversions

Visual Basic does not convert directly between Char and the numeric types. You can use the Asc or AscW function to convert a Char value to an Integer that represents its code point. You can use the Chr or ChrW function to convert an Integer value to a Char that has that code point.

If the type checking switch (the Option Strict Statement) is on, you must append the literal type character to a single-character string literal to identify it as the Char data type.

Programming Tips

  • Negative Numbers. Char is an unsigned type and cannot represent a negative value. In any case, you should not use Char to hold numeric values.

  • Interop Considerations. If you interface with components not written for the .NET Framework, for example Automation or COM objects, remember that character types have a different data width (8 bits) in other environments. If you pass an 8-bit argument to such a component, declare it as Byte instead of Char in your new Visual Basic code.

  • Widening. The Char data type widens to String. This means you can convert Char to String and will not encounter a System.OverflowException.

  • Type Characters. Appending the literal type character C to a single-character string literal forces it to the Char data type. Char has no identifier type character.

  • Framework Type. The corresponding type in the .NET Framework is the System.Char structure.

See also

Date Data Type

Holds IEEE 64-bit (8-byte) values that represent dates ranging from January 1 of the year 0001 through December 31 of the year 9999, and times from 12:00:00 AM (midnight) through 11:59:59.9999999 PM. Each increment represents 100 nanoseconds of elapsed time since the beginning of January 1 of the year 1 in the Gregorian calendar. The maximum value represents 100 nanoseconds before the beginning of January 1 of the year 10000.


Use the Date data type to contain date values, time values, or date and time values.

The default value of Date is 0:00:00 (midnight) on January 1, 0001.

You can get the current date and time from the DateAndTime class.

Format Requirements

You must enclose a Date literal within number signs (# #). You must specify the date value in the format M/d/yyyy, for example #5/31/1993#, or yyyy-MM-dd, for example #1993-5-31#. You can use slashes when specifying the year first. This requirement is independent of your locale and your computer's date and time format settings.

The reason for this restriction is that the meaning of your code should never change depending on the locale in which your application is running. Suppose you hard-code a Date literal of #3/4/1998# and intend it to mean March 4, 1998. In a locale that uses mm/dd/yyyy, 3/4/1998 compiles as you intend. But suppose you deploy your application in many countries/regions. In a locale that uses dd/mm/yyyy, your hard-coded literal would compile to April 3, 1998. In a locale that uses yyyy/mm/dd, the literal would be invalid (April 1998, 0003) and cause a compiler error.


To convert a Date literal to the format of your locale, or to a custom format, supply the literal to the Format function, specifying either a predefined or user-defined date format.

Alternatively, you can use one of the overloaded constructors of the DateTime structure to assemble a date and time value.

Hour Format

You can specify the time value in either 12-hour or 24-hour format, for example #1:15:30 PM# or #13:15:30#. However, if you do not specify either the minutes or the seconds, you must specify AM or PM.

Date and Time Defaults

If you do not include a date in a date/time literal, Visual Basic sets the date part of the value to January 1, 0001. If you do not include a time in a date/time literal, Visual Basic sets the time part of the value to the start of the day, that is, midnight (0:00:00).

Type Conversions

If you convert a Date value to the String type, Visual Basic renders the date according to the short date format specified by the run-time locale, and it renders the time according to the time format (either 12-hour or 24-hour) specified by the run-time locale.

Programming Tips

  • Interop Considerations. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, keep in mind that date/time types in other environments are not compatible with the Visual Basic Date type. If you are passing a date/time argument to such a component, declare it as Double instead of Date in your new Visual Basic code, and use the conversion methods DateTime.FromOADate and DateTime.ToOADate.

  • Type Characters. Date has no literal type character or identifier type character. However, the compiler treats literals enclosed within number signs (# #) as Date.

  • Framework Type. The corresponding type in the .NET Framework is the System.DateTime structure.

See also

Decimal Data Type

Holds signed 128-bit (16-byte) values representing 96-bit (12-byte) integer numbers scaled by a variable power of 10. The scaling factor specifies the number of digits to the right of the decimal point; it ranges from 0 through 28. With a scale of 0 (no decimal places), the largest possible value is +/-79,228,162,514,264,337,593,543,950,335 (+/-7.9228162514264337593543950335E+28). With 28 decimal places, the largest value is +/-7.9228162514264337593543950335, and the smallest nonzero value is +/-0.0000000000000000000000000001 (+/-1E-28).


The Decimal data type provides the greatest number of significant digits for a number. It supports up to 29 significant digits and can represent values in excess of 7.9228 x 10^28. It is particularly suitable for calculations, such as financial, that require a large number of digits but cannot tolerate rounding errors.

The default value of Decimal is 0.

Programming Tips

  • Precision. Decimal is not a floating-point data type. The Decimal structure holds a binary integer value, together with a sign bit and an integer scaling factor that specifies what portion of the value is a decimal fraction. Because of this, Decimal numbers have a more precise representation in memory than floating-point types (Single and Double).

  • Performance. The Decimal data type is the slowest of all the numeric types. You should weigh the importance of precision against performance before choosing a data type.

  • Widening. The Decimal data type widens to Single or Double. This means you can convert Decimal to either of these types without encountering a System.OverflowException error.

  • Trailing Zeros. Visual Basic does not store trailing zeros in a Decimal literal. However, a Decimal variable preserves any trailing zeros acquired computationally.

  • Type Characters. Appending the literal type character D to a literal forces it to the Decimal data type. Appending the identifier type character @ to any identifier forces it to Decimal.

  • Framework Type. The corresponding type in the .NET Framework is the System.Decimal structure.


You might need to use the D type character to assign a large value to a Decimal variable or constant. This requirement is because the compiler interprets a literal as Long unless a literal type character follows the literal.

The declaration for bigDec1 doesn't produce an overflow because the value that's assigned to it falls within the range for Long. The Long value can be assigned to the Decimal variable.

The declaration for bigDec2 generates an overflow error because the value that's assigned to it is too large for Long. Because the numeric literal can't first be interpreted as a Long, it can't be assigned to the Decimal variable.

For bigDec3, the literal type character D solves the problem by forcing the compiler to interpret the literal as a Decimal instead of as a Long.

See also





ID: 200700026 Last Updated: 26/7/2020 Revision: 0 Ref:



  1. Active Server Pages,  ,
  2. ASP Overview,  ,
  3. ASP Best Practices,  ,
  4. ASP Built-in Objects,  ,
  5. Response Object,  ,
  6. Request Object,  ,
  7. Server Object (IIS),  ,
  8. Application Object (IIS),  ,
  9. Session Object (IIS),  ,
  10. ASPError Object,  ,
  11. ObjectContext Object (IIS),  ,
  12. Debugging Global.asa Files,  ,
  13. How to: Debug Global.asa files,  ,
  14. Calling COM Components from ASP Pages,  ,
  15. IIS ASP Scripting Reference,  ,
  16. ASP Keywords,  ,
  17. Creating Simple ASP Pages,  ,
  18. Including Files in ASP Applications,  ,
  19. ASP Overview,  ,
  20. FileSystemObject Object,  ,
  21.,  , ADO Object Model
  22. ADO Fundamentals,  ,

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna

Home 5






Hobbies 8


Chinese 1097

English 337

Reference 67


Hardware 151


Application 202

Digitization 25

Latex 9

Manim 123

Numeric 19


Web 285

Unicode 494


CSS 59


OS 391

DeskTop 7

Python 23



Formulas 8

Algebra 29

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21


Tables 8


Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5


Process Control 1

Acoustics 19

FiniteElement 2


Electric 27

Biology 1

Geography 1

Copyright © 2000-2020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019