Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Type of Data
Elementary Data Types
 Related Sections
  Numeric Data Types
 Integral Numeric Types
  Performance
  Large Integers
  Small Integers
  Unsigned Integers
 Nonintegral Numeric Types
  Performance
  Small Magnitudes
  Small Fractional Numbers
 See also
  Character Data Types
 Char Type
 String Type
 See also
  Miscellaneous Data Types
 Boolean Type
 Date Type
 Object Type
 See also
  Composite Data Types
 Data Types
 Structure Types
 Tuples
 Array Types
 Class Types
 See also
  How to: Hold More Than One Value in a Variable
  To hold more than one value in a variable
 See also
  Source/Reference

VB.NET Type of Data

Elementary Data Types

Visual Basic supplies a set of predefined data types, which you can use for many of your programming elements. This section describes these types and how to use them.

Note

Every elementary data type in Visual Basic is supported by a structure or a class that is in the System namespace. The compiler uses each data type keyword as an alias for the underlying structure or class. For example, declaring a variable by using the reserved word Byte is the same as declaring it by using the fully qualified structure name System.Byte.

Related Sections

Data Types
Introduces the Visual Basic data types and describes how to use them.

Data Types
Provides an overview of the elementary data types supplied by Visual Basic.

Numeric Data Types

Visual Basic supplies several numeric data types for handling numbers in various representations. Integral types represent only whole numbers (positive, negative, and zero), and nonintegral types represent numbers with both integer and fractional parts.

For a table showing a side-by-side comparison of the Visual Basic data types, see Data Types.

Integral Numeric Types

Integral data types are those that represent only numbers without fractional parts.

The signed integral data types are SByte Data Type (8-bit), Short Data Type (16-bit), Integer Data Type (32-bit), and Long Data Type (64-bit). If a variable always stores integers rather than fractional numbers, declare it as one of these types.

The unsigned integral types are Byte Data Type (8-bit), UShort Data Type (16-bit), UInteger Data Type (32-bit), and ULong Data Type (64-bit). If a variable contains binary data, or data of unknown nature, declare it as one of these types.

Performance

Arithmetic operations are faster with integral types than with other data types. They are fastest with the Integer and UInteger types in Visual Basic.

Large Integers

If you need to hold an integer larger than the Integer data type can hold, you can use the Long data type instead. Long variables can hold numbers from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807. Operations with Long are slightly slower than with Integer.

If you need even larger values, you can use the Decimal Data Type. You can hold numbers from -79,228,162,514,264,337,593,543,950,335 through 79,228,162,514,264,337,593,543,950,335 in a Decimal variable if you do not use any decimal places. However, operations with Decimal numbers are considerably slower than with any other numeric data type.

Small Integers

If you do not need the full range of the Integer data type, you can use the Short data type, which can hold integers from -32,768 through 32,767. For the smallest integer range, the SByte data type holds integers from -128 through 127. If you have a very large number of variables that hold small integers, the common language runtime can sometimes store your Short and SByte variables more efficiently and save memory consumption. However, operations with Short and SByte are somewhat slower than with Integer.

Unsigned Integers

If you know that your variable never needs to hold a negative number, you can use the unsigned typesByte, UShort, UInteger, and ULong. Each of these data types can hold a positive integer twice as large as its corresponding signed type (SByte, Short, Integer, and Long). In terms of performance, each unsigned type is exactly as efficient as its corresponding signed type. In particular, UInteger shares with Integer the distinction of being the most efficient of all the elementary numeric data types.

Nonintegral Numeric Types

Nonintegral data types are those that represent numbers with both integer and fractional parts.

The nonintegral numeric data types are Decimal (128-bit fixed point), Single Data Type (32-bit floating point), and Double Data Type (64-bit floating point). They are all signed types. If a variable can contain a fraction, declare it as one of these types.

Decimal is not a floating-point data type. Decimal numbers have a binary integer value and an integer scaling factor that specifies what portion of the value is a decimal fraction.

You can use Decimal variables for money values. The advantage is the precision of the values. The Double data type is faster and requires less memory, but it is subject to rounding errors. The Decimal data type retains complete accuracy to 28 decimal places.

Floating-point (Single and Double) numbers have larger ranges than Decimal numbers but can be subject to rounding errors. Floating-point types support fewer significant digits than Decimal but can represent values of greater magnitude.

Nonintegral number values can be expressed as mmmEeee, in which mmm is the mantissa (the significant digits) and eee is the exponent (a power of 10). The highest positive values of the nonintegral types are 7.9228162514264337593543950335E+28 for Decimal, 3.4028235E+38 for Single, and 1.79769313486231570E+308 for Double.

Performance

Double is the most efficient of the fractional data types, because the processors on current platforms perform floating-point operations in double precision. However, operations with Double are not as fast as with the integral types such as Integer.

Small Magnitudes

For numbers with the smallest possible magnitude (closest to 0), Double variables can hold numbers as small as -4.94065645841246544E-324 for negative values and 4.94065645841246544E-324 for positive values.

Small Fractional Numbers

If you do not need the full range of the Double data type, you can use the Single data type, which can hold floating-point numbers from -3.4028235E+38 through 3.4028235E+38. The smallest magnitudes for Single variables are -1.401298E-45 for negative values and 1.401298E-45 for positive values. If you have a very large number of variables that hold small floating-point numbers, the common language runtime can sometimes store your Single variables more efficiently and save memory consumption.

See also

Character Data Types

Visual Basic provides character data types to deal with printable and displayable characters. While they both deal with Unicode characters, Char holds a single character whereas String contains an indefinite number of characters.

For a table that displays a side-by-side comparison of the Visual Basic data types, see Data Types.

Char Type

The Char data type is a single two-byte (16-bit) Unicode character. If a variable always stores exactly one character, declare it as Char. For example:

VB
' Initialize the prefix variable to the character 'a'.
Dim prefix As Char = "a"

Each possible value in a Char or String variable is a code point, or character code, in the Unicode character set. Unicode characters include the basic ASCII character set, various other alphabet letters, accents, currency symbols, fractions, diacritics, and mathematical and technical symbols.

Note

The Unicode character set reserves the code points D800 through DFFF (55296 through 55551 decimal) for surrogate pairs, which require two 16-bit values to represent a single code point. A Char variable cannot hold a surrogate pair, and a String uses two positions to hold such a pair.

For more information, see Char Data Type.

String Type

The String data type is a sequence of zero or more two-byte (16-bit) Unicode characters. If a variable can contain an indefinite number of characters, declare it as String. For example:

VB
' Initialize the name variable to "Monday".
Dim name As String = "Monday"

For more information, see String Data Type.

See also

Miscellaneous Data Types

Visual Basic supplies several data types that are not oriented toward numbers or characters. Instead, they deal with specialized data such as yes/no values, date/time values, and object addresses.

For a table showing a side-by-side comparison of the Visual Basic data types, see Data Types.

Boolean Type

The Boolean Data Type is an unsigned value that is interpreted as either True or False. Its data width depends on the implementing platform. If a variable can contain only two-state values such as true/false, yes/no, or on/off, declare it as Boolean.

Date Type

The Date Data Type is a 64-bit value that holds both date and time information. Each increment represents 100 nanoseconds of elapsed time since the beginning (12:00 AM) of January 1 of the year 1 in the Gregorian calendar. If a variable can contain a date value, a time value, or both, declare it as Date.

Object Type

The Object Data Type is a 32-bit address that points to an object instance within your application or in some other application. An Object variable can refer to any object your application recognizes, or to data of any data type. This includes both value types, such as Integer, Boolean, and structure instances, and reference types, which are instances of objects created from classes such as String and Form, and array instances.

If a variable stores a pointer to an instance of a class that you do not know at compile time, or if it can point to data of various data types, declare it as Object.

The advantage of the Object data type is that you can use it to store data of any data type. The disadvantage is that you incur extra operations that take more execution time and make your application perform slower. If you use an Object variable for value types, you incur boxing and unboxing. If you use it for reference types, you incur late binding.

See also

Composite Data Types

In addition to the elementary data types Visual Basic supplies, you can also assemble items of different types to create composite data types such as structures, arrays, and classes. You can build composite data types from elementary types and from other composite types. For example, you can define an array of structure elements, or a structure with array members.

Data Types

A composite type is different from the data type of any of its components. For example, an array of Integer elements is not of the Integer data type.

An array data type is normally represented using the element type, parentheses, and commas as necessary. For example, a one-dimensional array of String elements is represented as String(), and a two-dimensional array of Boolean elements is represented as Boolean(,).

Structure Types

There is no single data type comprising all structures. Instead, each definition of a structure represents a unique data type, even if two structures define identical elements in the same order. However, if you create two or more instances of the same structure, Visual Basic considers them to be of the same data type.

Tuples

A tuple is a lightweight structure that contains two or more fields whose types are predefined. Tuples are supported starting with Visual Basic 2017. Tuples are most commonly used to return multiple values from a single method call without having to pass arguments by reference or packaging the returned fields in a more heavy-weight class or structure. See the Tuples topic for more information on tuples.

Array Types

There is no single data type comprising all arrays. The data type of a particular instance of an array is determined by the following:

  • The fact of being an array

  • The rank (number of dimensions) of the array

  • The element type of the array

In particular, the length of a given dimension is not part of the instance's data type. The following example illustrates this.

Dim arrayA( ) As Byte = New Byte(12) {}  
Dim arrayB( ) As Byte = New Byte(100) {}  
Dim arrayC( ) As Short = New Short(100) {}  
Dim arrayD( , ) As Short  
Dim arrayE( , ) As Short = New Short(4, 10) {}  

In the preceding example, array variables arrayA and arrayB are considered to be of the same data type — Byte() — even though they are initialized to different lengths. Variables arrayB and arrayC are not of the same type because their element types are different. Variables arrayC and arrayD are not of the same type because their ranks are different. Variables arrayD and arrayE have the same type — Short(,) — because their ranks and element types are the same, even though arrayD is not yet initialized.

For more information on arrays, see Arrays.

Class Types

There is no single data type comprising all classes. Although one class can inherit from another class, each is a separate data type. Multiple instances of the same class are of the same data type. If you assign one class instance variable to another, not only do they have the same data type, they point to the same class instance in memory.

For more information on classes, see Objects and Classes.

See also

How to: Hold More Than One Value in a Variable

A variable holds more than one value if you declare it to be of a composite data type.

Composite Data Types include structures, arrays, and classes. A variable of a composite data type can hold a combination of elementary data types and other composite types. Structures and classes can hold code as well as data.

To hold more than one value in a variable

  1. Determine what composite data type you want to use for your variable.

  2. If the composite data type is not already defined, define it so that your variable can use it.

  3. Declare your variable with a Dim statement.

  4. Follow the variable name with an As clause.

  5. Follow the As keyword with the name of the appropriate composite data type.

See also

 

Source/Reference


©sideway

ID: 200900018 Last Updated: 9/18/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

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

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


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