Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Data Types
  SByte Data Type
  Remarks
  Literal assignments
  Programming tips
  See also
  Short data type
  Remarks
  Literal assignments
  Programming tips
  See also
  Integer data type
  Remarks
  Literal assignments
  Programming tips
  Range
  See also
  Long data type
  Remarks
  Literal assignments
  Programming tips
  See also
  Source/Reference

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)

SByte Data Type

Holds signed 8-bit (1-byte) integers that range in value from -128 through 127.

Remarks

Use the SByte data type to contain integer values that do not require the full data width of Integer or even the half data width of Short. In some cases, the common language runtime might be able to pack your SByte variables closely together and save memory consumption.

The default value of SByte is 0.

Literal assignments

You can declare and initialize an SByte variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal.

Note

You use the prefix &h or &H to denote a hexadecimal literal, the prefix &b or &B to denote a binary literal, and the prefix &o or &O to denote an octal literal. Decimal literals have no prefix.

Starting with Visual Basic 2017, you can also use the underscore character, _, as a digit separator to enhance readability.

Starting with Visual Basic 15.5, you can also use the underscore character (_) as a leading separator between the prefix and the hexadecimal, binary, or octal digits.

To use the underscore character as a leading separator, you must add the following element to your Visual Basic project (*.vbproj) file:

XML
<PropertyGroup>
  <LangVersion>15.5</LangVersion>
</PropertyGroup>

For more information see setting the Visual Basic language version.

If the integer literal is outside the range of SByte (that is, if it is less than SByte.MinValue or greater than SByte.MaxValue, a compilation error occurs. When an integer literal has no suffix, an Integer is inferred. If the integer literal is outside the range of the Integer type, a Long is inferred. This means that, in the previous examples, the numeric literals 0x9A and 0b10011010 are interpreted as 32-bit signed integers with a value of 156, which exceeds SByte.MaxValue. To successfully compile code like this that assigns a non-decimal integer to an SByte, you can do either of the following:

  • Disable integer bounds checks by compiling with the /removeintchecks compiler switch.

  • Use a type character to explicitly define the literal value that you want to assign to the SByte. The following example assigns a negative literal Short value to an SByte. Note that, for negative numbers, the high-order bit of the high-order word of the numeric literal must be set.

Programming tips

  • CLS Compliance. The SByte data type is not part of the Common Language Specification (CLS), so CLS-compliant code cannot consume a component that uses it.

  • Widening. The SByte data type widens to Short, Integer, Long, Decimal, Single, and Double. This means you can convert SByte to any of these types without encountering a System.OverflowException error.

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

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

See also

Short data type

Holds signed 16-bit (2-byte) integers that range in value from -32,768 through 32,767.

Remarks

Use the Short data type to contain integer values that do not require the full data width of Integer. In some cases, the common language runtime can pack your Short variables closely together and save memory consumption.

The default value of Short is 0.

Literal assignments

You can declare and initialize a Short variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. If the integer literal is outside the range of Short (that is, if it is less than Int16.MinValue or greater than Int16.MaxValue, a compilation error occurs.

Note

You use the prefix &h or &H to denote a hexadecimal literal, the prefix &b or &B to denote a binary literal, and the prefix &o or &O to denote an octal literal. Decimal literals have no prefix.

Starting with Visual Basic 2017, you can also use the underscore character, _, as a digit separator to enhance readability.

Starting with Visual Basic 15.5, you can also use the underscore character (_) as a leading separator between the prefix and the hexadecimal, binary, or octal digits.

To use the underscore character as a leading separator, you must add the following element to your Visual Basic project (*.vbproj) file:

XML
<PropertyGroup>
  <LangVersion>15.5</LangVersion>
</PropertyGroup>

 

For more information see setting the Visual Basic language version.

Numeric literals can also include the S type character to denote the Short data type.

Programming tips

  • Widening. The Short data type widens to Integer, Long, Decimal, Single, or Double. This means you can convert Short to any one of these types without encountering a System.OverflowException error.

  • Type Characters. Appending the literal type character S to a literal forces it to the Short data type. Short has no identifier type character.

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

See also

Integer data type

Holds signed 32-bit (4-byte) integers that range in value from -2,147,483,648 through 2,147,483,647.

Remarks

The Integer data type provides optimal performance on a 32-bit processor. The other integral types are slower to load and store from and to memory.

The default value of Integer is 0.

Literal assignments

You can declare and initialize an Integer variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. If the integer literal is outside the range of Integer (that is, if it is less than Int32.MinValue or greater than Int32.MaxValue, a compilation error occurs.

Note

You use the prefix &h or &H to denote a hexadecimal literal, the prefix &b or &B to denote a binary literal, and the prefix &o or &O to denote an octal literal. Decimal literals have no prefix.

Starting with Visual Basic 2017, you can also use the underscore character, _, as a digit separator to enhance readability.

Starting with Visual Basic 15.5, you can also use the underscore character (_) as a leading separator between the prefix and the hexadecimal, binary, or octal digits.

To use the underscore character as a leading separator, you must add the following element to your Visual Basic project (*.vbproj) file:

XML
<PropertyGroup>
  <LangVersion>15.5</LangVersion>
</PropertyGroup>

For more information see setting the Visual Basic language version.

Numeric literals can also include the I type character to denote the Integer data type.

Programming tips

  • Interop Considerations. If you are interfacing with components not written for the .NET Framework, such as Automation or COM objects, remember that Integer has a different data width (16 bits) in other environments. If you are passing a 16-bit argument to such a component, declare it as Short instead of Integer in your new Visual Basic code.

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

  • Type Characters. Appending the literal type character I to a literal forces it to the Integer data type. Appending the identifier type character % to any identifier forces it to Integer.

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

Range

If you try to set a variable of an integral type to a number outside the range for that type, an error occurs. If you try to set it to a fraction, the number is rounded up or down to the nearest integer value. If the number is equally close to two integer values, the value is rounded to the nearest even integer. This behavior minimizes rounding errors that result from consistently rounding a midpoint value in a single direction.

See also

Long data type

Holds signed 64-bit (8-byte) integers ranging in value from -9,223,372,036,854,775,808 through 9,223,372,036,854,775,807 (9.2...E+18).

Remarks

Use the Long data type to contain integer numbers that are too large to fit in the Integer data type.

The default value of Long is 0.

Literal assignments

You can declare and initialize a Long variable by assigning it a decimal literal, a hexadecimal literal, an octal literal, or (starting with Visual Basic 2017) a binary literal. If the integer literal is outside the range of Long (that is, if it is less than Int64.MinValue or greater than Int64.MaxValue, a compilation error occurs.

Note

You use the prefix &h or &H to denote a hexadecimal literal, the prefix &b or &B to denote a binary literal, and the prefix &o or &O to denote an octal literal. Decimal literals have no prefix.

Starting with Visual Basic 2017, you can also use the underscore character, _, as a digit separator to enhance readability.

Starting with Visual Basic 15.5, you can also use the underscore character (_) as a leading separator between the prefix and the hexadecimal, binary, or octal digits.

To use the underscore character as a leading separator, you must add the following element to your Visual Basic project (*.vbproj) file:

XML
<PropertyGroup>
  <LangVersion>15.5</LangVersion>
</PropertyGroup>

For more information see setting the Visual Basic language version.

Numeric literals can also include the L type character to denote the Long data type.

Programming tips

  • Interop Considerations. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, remember that Long has a different data width (32 bits) in other environments. If you are passing a 32-bit argument to such a component, declare it as Integer instead of Long in your new Visual Basic code.

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

  • Type Characters. Appending the literal type character L to a literal forces it to the Long data type. Appending the identifier type character & to any identifier forces it to Long.

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

See also

Source/Reference


©sideway

ID: 200700028 Last Updated: 7/28/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