Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Data
 Declared Data Types
 See also
  Type characters
 Identifier type characters
 Literal type characters
  Default literal types
  Forced literal types
 Hexadecimal, binary, and octal literals
 See also
  Source/Reference

VB.NET Data

The data type of a programming element refers to what kind of data it can hold and how it stores that data. Data types apply to all values that can be stored in computer memory or participate in the evaluation of an expression. Every variable, literal, constant, enumeration, property, procedure parameter, procedure argument, and procedure return value has a data type.

Declared Data Types

You define a programming element with a declaration statement, and you specify its data type with the As clause. The following table shows the statements you use to declare various elements.

Programming element Data type declaration
Variable In a Dim Statement

Dim amount As Double

Static yourName As String

Public billsPaid As Decimal = 0
Literal With a literal type character; see "Literal Type Characters" in Type Characters

Dim searchChar As Char = "." C
Constant In a Const Statement

Const modulus As Single = 4.17825F
Enumeration In an Enum Statement

Public Enum colors
Property In a Property Statement

Property region() As String
Procedure parameter In a Sub Statement, Function Statement, or Operator Statement

Sub addSale(ByVal amount As Double)
Procedure argument In the calling code; each argument is a programming element that has already been declared, or an expression containing declared elements

subString = Left( inputString , 5 )
Procedure return value In a Function Statement or Operator Statement

Function convert(ByVal b As Byte) As String

For a list of Visual Basic data types, see Data Types.

See also

Type characters

In addition to specifying a data type in a declaration statement, you can force the data type of some programming elements with a type character. The type character must immediately follow the element, with no intervening characters of any kind.

The type character is not part of the name of the element. An element defined with a type character can be referenced without the type character.

Identifier type characters

Visual Basic supplies a set of identifier type characters that you can use in a declaration to specify the data type of a variable or constant. The following table shows the available identifier type characters with examples of usage.

Identifier type character Data type Example
% Integer Dim L%
& Long Dim M&
@ Decimal Const W@ = 37.5
! Single Dim Q!
# Double Dim X#
$ String Dim V$ = "Secret"

No identifier type characters exist for the Boolean, Byte, Char, Date, Object, SByte, Short, UInteger, ULong, or UShort data types, or for any composite data types such as arrays or structures.

In some cases, you can append the $ character to a Visual Basic function, for example Left$ instead of Left, to obtain a returned value of type String.

In all cases, the identifier type character must immediately follow the identifier name.

Literal type characters

A literal is a textual representation of a particular value of a data type.

Default literal types

The form of a literal as it appears in your code ordinarily determines its data type. The following table shows these default types.

Textual form of literal Default data type Example
Numeric, no fractional part Integer 2147483647
Numeric, no fractional part, too large for Integer Long 2147483648
Numeric, fractional part Double 1.2
Enclosed in double quotation marks String "A"
Enclosed within number signs Date #5/17/1993 9:32 AM#

Forced literal types

Visual Basic supplies a set of literal type characters, which you can use to force a literal to assume a data type other than the one its form indicates. You do this by appending the character to the end of the literal. The following table shows the available literal type characters with examples of usage.

Literal type character Data type Example
S Short I = 347S
I Integer J = 347I
L Long K = 347L
D Decimal X = 347D
F Single Y = 347F
R Double Z = 347R
US UShort L = 347US
UI UInteger M = 347UI
UL ULong N = 347UL
C Char Q = "."C

No literal type characters exist for the Boolean, Byte, Date, Object, SByte, or String data types, or for any composite data types such as arrays or structures.

Literals can also use the identifier type characters (%, &, @, !, #, $), as can variables, constants, and expressions. However, the literal type characters (S, I, L, D, F, R, C) can be used only with literals.

In all cases, the literal type character must immediately follow the literal value.

Hexadecimal, binary, and octal literals

The compiler normally interprets an integer literal to be in the decimal (base 10) number system. You can also define an integer literal as a hexadecimal (base 16) number with the &H prefix, as a binary (base 2) number with the &B prefix, and as an octal (base 8) number with the &O prefix. The digits that follow the prefix must be appropriate for the number system. The following table illustrates this.

Number base Prefix Valid digit values Example
Hexadecimal (base 16) &H 0-9 and A-F &HFFFF
Binary (base 2) &B 0-1 &B01111100
Octal (base 8) &O 0-7 &O77

Starting in Visual Basic 2017, you can use the underscore character (_) as a group separator to enhance the readability of an integral literal. The following example uses the _ character to group a binary literal into 8-bit groups:

VB
Dim number As Integer = &B00100010_11000101_11001111_11001101

You can follow a prefixed literal with a literal type character. The following example shows this.

VB
Dim counter As Short = &H8000S
Dim flags As UShort = &H8000US

In the previous example, counter has the decimal value of -32768, and flags has the decimal value of +32768.

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. For example:

VB
Dim number As Integer = &H_C305_F860

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.

See also

 

Source/Reference


©sideway

ID: 200900017 Last Updated: 17/9/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
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 151

Software

Application 198

Digitization 25

Latex 9

Manim 121

Numeric 19

Programming

Web 283

Unicode 494

HTML 65

CSS 58

ASP.NET 174

OS 389

DeskTop 7

Python 19

Knowledge

Mathematics

Formulas 8

Algebra 25

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