Examples: CLng function

Example 1

' Convert string to long
' Display value and data type
Dim nvar As Variant
Dim nstr As String
nstr = Inputbox("Number", "Enter any number", "0")
If Isnumeric(nstr) Then
	nvar = Clng(nstr)
	Messagebox nvar,, Typename(nvar)
	Messagebox nstr,, "Not a number"
End Sub

Example 2

' Convert Double and String values to Long, rounding up or down as indicated.
Dim x As Double, y as String
x# = 13.400556
Print CLng(x#)	'Prints 13

x# = 13.67
Print CLng(x#)	'Prints 14

Print CLng(y)		'Prints 1

Print CLng(y)		'Prints 2

Print CLng(y)		'returns a type mismatch error