
214
|
Chapter 12: The Language Reference
This is the Title of the Book, eMatter Edition
Copyright © 2006 O’Reilly & Associates, Inc. All rights reserved.
Example
Dim targetNumber As Short
If IsNumeric(stringNumber) Then
targetNumber = CShort(stringNumber)
End If
Version Differences
The CShort function is new to VB under .NET. However, it corresponds directly to the
VB 6
CInt function, since both return 16-bit integers.
See Also
CInt Function, CLng Function, CUShort Function
CSng Function
Syntax
Dim result As Single = CSng(expression)
expression (required; Numeric or String)
Any expression in the valid range of the
Single data type.
Description
The CSng function converts expression to the Single data type.
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.
Example
Dim targetNumber As Single
If IsNumeric(stringNumber) Then
targetNumber = CSng(stringNumber)
End If
See Also
CDbl Function
CStr Function
Syntax
Dim result As String = CStr(expression ...