Sideway from Sideway
Draft for Information Only


VB.NET Data Types
  String Data Type
  Unicode Characters
  Format Requirements
  String Manipulations
  Programming Tips
  See also
  Object Data Type
  Data Types
  Programming Tips
  See also
  User-Defined Data Type
  Declaration Format
  Member Access Levels
  Programming Tips
  See also

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)

String Data Type

Holds sequences of unsigned 16-bit (2-byte) code points that range in value from 0 through 65535. Each code point, or character code, represents a single Unicode character. A string can contain from 0 to approximately two billion (2 ^ 31) Unicode characters.


Use the String data type to hold multiple characters without the array management overhead of Char(), an array of Char elements.

The default value of String is Nothing (a null reference). Note that this is not the same as the empty string (value "").

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. This includes worldwide textual characters, diacritics, and mathematical and technical symbols.

You can use methods such as IsDigit and IsPunctuation on an individual character in a String variable to determine its Unicode classification.

Format Requirements

You must enclose a String literal within quotation marks (" "). If you must include a quotation mark as one of the characters in the string, you use two contiguous quotation marks ("").

Note that the contiguous quotation marks that represent a quotation mark in the string are independent of the quotation marks that begin and end the String literal.

String Manipulations

Once you assign a string to a String variable, that string is immutable, which means you cannot change its length or contents. When you alter a string in any way, Visual Basic creates a new string and abandons the previous one. The String variable then points to the new string.

You can manipulate the contents of a String variable by using a variety of string functions.

A string created by another component might be padded with leading or trailing spaces. If you receive such a string, you can use the Trim, LTrim, and RTrim functions to remove these spaces.

For more information about string manipulations, see Strings.

Programming Tips

  • Negative Numbers. Remember that the characters held by String are unsigned and cannot represent negative values. In any case, you should not use String to hold numeric values.

  • Interop Considerations. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, remember that string characters have a different data width (8 bits) in other environments. If you are passing a string argument of 8-bit characters to such a component, declare it as Byte(), an array of Byte elements, instead of String in your new Visual Basic code.

  • Type Characters. Appending the identifier type character $ to any identifier forces it to the String data type. String has no literal type character. However, the compiler treats literals enclosed in quotation marks (" ") as String.

  • Framework Type. The corresponding type in the .NET Framework is the System.String class.

See also

Object Data Type

Holds addresses that refer to objects. You can assign any reference type (string, array, class, or interface) to an Object variable. An Object variable can also refer to data of any value type (numeric, Boolean, Char, Date, structure, or enumeration).


The Object data type can point to data of any data type, including any object instance your application recognizes. Use Object when you do not know at compile time what data type the variable might point to.

The default value of Object is Nothing (a null reference).

Data Types

You can assign a variable, constant, or expression of any data type to an Object variable. To determine the data type an Object variable currently refers to, you can use the GetTypeCode method of the System.Type class.

The Object data type is a reference type. However, Visual Basic treats an Object variable as a value type when it refers to data of a value type.


Whatever data type it refers to, an Object variable does not contain the data value itself, but rather a pointer to the value. It always uses four bytes in computer memory, but this does not include the storage for the data representing the value of the variable. Because of the code that uses the pointer to locate the data, Object variables holding value types are slightly slower to access than explicitly typed variables.

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 pointer types in other environments are not compatible with the Visual Basic Object type.

  • Performance. A variable you declare with the Object type is flexible enough to contain a reference to any object. However, when you invoke a method or property on such a variable, you always incur late binding (at run time). To force early binding (at compile time) and better performance, declare the variable with a specific class name, or cast it to the specific data type.

    When you declare an object variable, try to use a specific class type, for example OperatingSystem, instead of the generalized Object type. You should also use the most specific class available, such as TextBox instead of Control, so that you can access its properties and methods. You can usually use the Classes list in the Object Browser to find available class names.

  • Widening. All data types and all reference types widen to the Object data type. This means you can convert any type to Object without encountering a System.OverflowException error.

    However, if you convert between value types and Object, Visual Basic performs operations called boxing and unboxing, which make execution slower.

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

  • Framework Type. The corresponding type in the .NET Framework is the System.Object class.

See also

User-Defined Data Type

Holds data in a format you define. The Structure statement defines the format.

Previous versions of Visual Basic support the user-defined type (UDT). The current version expands the UDT to a structure. A structure is a concatenation of one or more members of various data types. Visual Basic treats a structure as a single unit, although you can also access its members individually.


Define and use a structure data type when you need to combine various data types into a single unit, or when none of the elementary data types serve your needs.

The default value of a structure data type consists of the combination of the default values of each of its members.

Declaration Format

A structure declaration starts with the Structure Statement and ends with the End Structure statement. The Structure statement supplies the name of the structure, which is also the identifier of the data type the structure is defining. Other parts of the code can use this identifier to declare variables, parameters, and function return values to be of this structure's data type.

The declarations between the Structure and End Structure statements define the members of the structure.

Member Access Levels

You must declare every member using a Dim Statement or a statement that specifies access level, such as Public, Friend, or Private. If you use a Dim statement, the access level defaults to public.

Programming Tips

  • Memory Consumption. As with all composite data types, you cannot safely calculate the total memory consumption of a structure by adding together the nominal storage allocations of its members. Furthermore, you cannot safely assume that the order of storage in memory is the same as your order of declaration. If you need to control the storage layout of a structure, you can apply the StructLayoutAttribute attribute to the Structure statement.

  • Interop Considerations. If you are interfacing with components not written for the .NET Framework, for example Automation or COM objects, keep in mind that user-defined types in other environments are not compatible with Visual Basic structure types.

  • Widening. There is no automatic conversion to or from any structure data type. You can define conversion operators on your structure using the Operator Statement, and you can declare each conversion operator to be Widening or Narrowing.

  • Type Characters. Structure data types have no literal type character or identifier type character.

  • Framework Type. There is no corresponding type in the .NET Framework. All structures inherit from the .NET Framework class System.ValueType, but no individual structure corresponds to System.ValueType.

See also



ID: 200700025 Last Updated: 25/7/2020 Revision: 0 Ref:



  1. Active Server Pages,  ,
  2. ASP Overview,  ,
  3. ASP Best Practices,  ,
  4. ASP Built-in Objects,  ,
  5. Response Object,  ,
  6. Request Object,  ,
  7. Server Object (IIS),  ,
  8. Application Object (IIS),  ,
  9. Session Object (IIS),  ,
  10. ASPError Object,  ,
  11. ObjectContext Object (IIS),  ,
  12. Debugging Global.asa Files,  ,
  13. How to: Debug Global.asa files,  ,
  14. Calling COM Components from ASP Pages,  ,
  15. IIS ASP Scripting Reference,  ,
  16. ASP Keywords,  ,
  17. Creating Simple ASP Pages,  ,
  18. Including Files in ASP Applications,  ,
  19. ASP Overview,  ,
  20. FileSystemObject Object,  ,
  21.,  , ADO Object Model
  22. ADO Fundamentals,  ,

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

Home 5






Hobbies 8


Chinese 1097

English 337

Reference 67


Hardware 151


Application 202

Digitization 25

Latex 9

Manim 123

Numeric 19


Web 285

Unicode 494


CSS 59


OS 391

DeskTop 7

Python 23



Formulas 8

Algebra 29

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21


Tables 8


Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5


Process Control 1

Acoustics 19

FiniteElement 2


Electric 27

Biology 1

Geography 1

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