IsNumeric Method

Information.IsNumeric Method (Object)

 

Returns a Boolean value indicating whether an expression can be evaluated as a number.

Namespace:   Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)

public static bool IsNumeric(
	object Expression
)

Parameters

Expression
Type: System.Object

Required. Object expression.

Return Value

Type: System.Boolean

Returns a Boolean value indicating whether an expression can be evaluated as a number.

IsNumeric returns True if the data type of Expression is Boolean, Byte, Decimal, Double, Integer, Long, SByte, Short, Single, UInteger, ULong, or UShort. It also returns True if Expression is a Char, String, or Object that can be successfully converted to a number. Expression can contain non-numeric characters. IsNumeric returns True if Expression is a string that contains a valid hexadecimal or octal number. IsNumeric also returns True if Expression contains a valid numeric expression that begins with a + or - character or contains commas.

IsNumeric returns False if Expression is of data type Date. It returns False if Expression is a Char, String, or Object that cannot be successfully converted to a number.

The following example uses the IsNumeric function to determine if the contents of a variable can be evaluated as a number.

Dim testVar As Object
Dim numericCheck As Boolean
testVar = "53"
' The following call to IsNumeric returns True.
numericCheck = IsNumeric(testVar)
testVar = "459.95"
' The following call to IsNumeric returns True.
numericCheck = IsNumeric(testVar)
testVar = "45 Help"
' The following call to IsNumeric returns False.
numericCheck = IsNumeric(testVar)

.NET Framework
Available since 1.1
Return to top
Show:
© 2016 Microsoft