Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Data Types
  Boolean Data Type
  Remarks
  Type Conversions
  Programming Tips
  See also
  Char Data Type
  Remarks
  Unicode Characters
  Type Conversions
  Programming Tips
  See also
  Date Data Type
  Remarks
  Format Requirements
  Workarounds
  Hour Format
  Date and Time Defaults
  Type Conversions
  Programming Tips
  See also
  Decimal Data Type
  Remarks
  Programming Tips
  Range
  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)

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.

Remarks

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.

Remarks

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.

Remarks

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.

Workarounds

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

Remarks

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.

Range

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

 

Source/Reference

 


©sideway

ID: 200700026 Last Updated: 26/7/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 337

Reference 67

Computer

Hardware 151

Software

Application 202

Digitization 25

Latex 9

Manim 123

Numeric 19

Programming

Web 285

Unicode 494

HTML 65

CSS 59

ASP.NET 194

OS 391

DeskTop 7

Python 23

Knowledge

Mathematics

Formulas 8

Algebra 29

Number Theory 206

Trigonometry 18

Geometry 21

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

Physics

Electric 27

Biology 1

Geography 1


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