CLng - VBScript


CLng

Overview

CLng converts a numeric expression to a Long integer (32-bit integer). It is commonly used for data type conversion, particularly when dealing with numeric values stored as text or strings.

Syntax

CLng(expr)

Where:

  • expr: Numeric expression to be converted to Long integer.

Options/Flags

None

Examples

' Convert a string representation of a number to Long
Dim number = "12345"
Dim convertedNumber = CLng(number)

' Convert a hexadecimal string to Long
Dim hexNumber = "&H12345"
Dim convertedHexNumber = CLng(hexNumber)

' Use CLng to ensure compatibility with 32-bit systems
Dim largeNumber = "9223372036854775807"
Dim convertedLargeNumber = CLng(largeNumber)

Common Issues

  • Ensure that the input expression can be converted to a valid Long integer. If the expression is outside the range of a Long integer (-2^31 to 2^31-1), an error will occur.
  • Avoid using CLng with non-numeric expressions, as it can lead to unexpected results or errors.

Integration

CLng can be used in conjunction with other VB Script commands for advanced data manipulation tasks. For example:

' Convert a string to Long and use it in a calculation
Dim numberString = "50"
Dim result = 100 + CLng(numberString)

Related Commands

  • CInt: Converts to a 16-bit integer (Integer)
  • CDbl: Converts to a double-precision floating-point number (Double)
  • CSng: Converts to a single-precision floating-point number (Single)