Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Efficient Use of Data Types

Efficient Use of Data Types

Undeclared variables and variables declared without a data type are given the Object data type. This makes it easy to write programs quickly, but it can cause them to execute more slowly.

Specifying data types for all your variables is known as strong typing. Using strong typing has several advantages:

  • It enables IntelliSense™ support for your variables. This allows you to see their properties and other members as you type in the code.
  • It allows the compiler to perform type checking. This catches statements that can fail at run time due to errors such as overflow. It also catches calls to methods on objects that do not support them.
  • It results in faster execution of your code.

For variables that never contain fractions, the integral data types are more efficient than the nonintegral types. In Visual Basic .NET, Integer is the most efficient numeric type.

Use the Dim statement to declare a variable of a specific type. You can simultaneously specify its accessibility by using the Public, Protected, Friend, or Private keyword, as in the following example:

Private X As Double   ' X is a double-precision floating point.
Protected S As String   ' S is a character string.

Character Conversion

The AscW and ChrW functions operate in Unicode. You should use them in preference to Asc and Chr, which must translate into and out of Unicode.

See Also

Data Types | Data Type Declaration | Numeric Data Types | Variable Declaration | Asc, AscW Functions | Chr, ChrW Functions

Show:
© 2015 Microsoft