Home

VBA Data Types: Integer

 

Introduction

To declare a variable that would hold a number that ranges from -32768 to 32767, use the Integer data type. Here is an example of declaring an integer variable:

Sub Exercise()
    Dim Tracks As Integer
End Sub

Instead of using As Integer, you can use the % type character. Therefore, the above declaration could be done as follows:

Sub Exercise()
    Dim Tracks%
End Sub

After declaring the variable, you can assign the desired value to it. If you assign a value lower than -32768 or higher than 32767, when you decide to use it, you would receive an error.

If you have a value that needs to be converted into a natural number, you can use CInt() using the following formula:

Number = CInt(Value to Convert)

Between the parentheses of CInt(), enter the value, text, or expression that needs to be converted.  

 
 
     
 

Home Copyright © 2009-2016, FunctionX, Inc.