Share via


Data Types in Visual Basic

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 (Visual Basic)

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 (Visual Basic)

Dim searchChar As Char = "."C

Constant

In a Const Statement (Visual Basic)

Const modulus As Single = 4.17825F

Enumeration

In an Enum Statement (Visual Basic)

Public Enum colors

Property

In a Property Statement

Property region() As String

Procedure parameter

In a Sub Statement (Visual Basic), Function Statement (Visual Basic), 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 (Visual Basic) or Operator Statement

Function convert(ByVal b As Byte) As String

For a list of Visual Basic data types, see Data Type Summary (Visual Basic).

See Also

Tasks

Troubleshooting Data Types (Visual Basic)

Reference

Data Type Summary (Visual Basic)

Concepts

Type Characters (Visual Basic)

Composite Data Types (Visual Basic)

Generic Types in Visual Basic (Visual Basic)

Value Types and Reference Types

Efficient Use of Data Types (Visual Basic)

Other Resources

Elementary Data Types (Visual Basic)

Type Conversions in Visual Basic

Structures (Visual Basic)