Home

VBA Data Types: Single

 

Introduction

In computer programming, a decimal number is one that represents a fraction. Examples are 1.85 or 426.88. If you plan to use a variable that would that type of number but precision is not your main concern, declare it using the Single data type. Here is an example:

Sub Exercise()
    Dim Distance As Single
End Sub

The type character for the Single data type is !. Based on this, the above declaration could be done as:

Sub Exercise()
    Dim Distance!
End Sub

A Single variable can hold a number between 1.401298e–45 and 3.402823e38. for negative values or between 1.401298e–45 and 3.402823e38 for positive values.

To convert a value to Single, you can call the CSng() function:

Number = CSng(Value to Convert)

In the parentheses of CSng(), enter the value to be converted.

 
 
     
 

Home Copyright © 2009-2016, FunctionX, Inc.