Training
Module
Choose the correct data type in your C# code - Training
Choose the correct data type for your code from several basic types used in C#.
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Unless otherwise specified, undeclared variables are assigned the Variant data type. This data type makes it easy to write programs, but it is not always the most efficient data type to use.
You should consider using other data types if:
In addition to Variant, supported data types include Byte, Boolean, Integer, Long, Single, Double, Currency, Decimal, Date, Object, and String.
Use the Dim statement to declare a variable of a specific type, for example:
Dim X As Integer
This statement declares that a variable X
is an integer — a whole number between -32,768 and 32,767. If you try to set X
to a number outside that range, an error occurs. If you try to set X
to a fraction, the number is rounded. For example:
X = 32768 ' Causes error.
X = 5.9 ' Sets x to 6.
Have questions or feedback about Office VBA or this documentation? Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.
Training
Module
Choose the correct data type in your C# code - Training
Choose the correct data type for your code from several basic types used in C#.