Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))

CUInt Function

Syntax

Dim result As UInteger = CUInt(expression)

expression (required; Numeric or String)

Any expression in the valid range of the UInteger data type

Description

New in 2005. The CUInt function converts expression to the UInteger data type; any fractional portion of expression is rounded.

Usage at a Glance

  • An expression that evaluates outside the valid range of the target data type results in a runtime error. Nonnumeric expressions also generate an error.

  • In most cases, the numeric conversion functions are a better choice than the Val function when converting a string, as the conversion functions take into account the system's regional settings. However, Val converts empty strings to zero without error.

  • Use IsNumeric to test whether expression evaluates to a number.

  • This function does not support named arguments.

  • CUInt differs from the Fix and Int functions, which truncate, rather than round, the fractional part of a number. Also, Fix and Int always return the same data type as what was passed in.

Example

Dim targetNumber As UInteger If IsNumeric(stringNumber) Then targetNumber = CUInt(stringNumber) End If

Version Differences

The CUInt function is new in the 2005 version of VB.

See Also

CInt Function, CULng Function, CUShort Function

Категории