Mega Code Archive

 
Categories / VB.Net Tutorial / Data Type
 

IsNumeric, IsDate, IsNothing

Public Class Tester     Public Shared Sub Main         Dim theData As String = Nothing         Dim result As New System.Text.StringBuilder         ' ----- Format nothing.         result.AppendLine(String.Format( _            "IsNumeric({0}) ... {1}", theData, IsNumeric(theData)))         result.AppendLine(String.Format( _            "IsDate({0}) ... {1}", theData, IsDate(theData)))         result.AppendLine(String.Format( _            "IsNothing({0}) ... {1}", theData, IsNothing(theData)))         result.AppendLine()         ' ----- Format a number in a string.         theData = "-12.345"         result.AppendLine(String.Format( _            "IsNumeric({0}) ... {1}", theData, IsNumeric(theData)))         result.AppendLine(String.Format( _            "IsDate({0}) ... {1}", theData, IsDate(theData)))         result.AppendLine(String.Format( _            "IsNothing({0}) ... {1}", theData, IsNothing(theData)))         result.AppendLine()         ' ----- Format a date in a string.         theData = "July 17, 2007"         result.AppendLine(String.Format( _            "IsNumeric({0}) ... {1}", theData, IsNumeric(theData)))         result.AppendLine(String.Format( _            "IsDate({0}) ... {1}", theData, IsDate(theData)))         result.Append(String.Format( _            "IsNothing({0}) ... {1}", theData, IsNothing(theData)))         Console.WriteLine(result.ToString())     End Sub End Class IsNumeric() ... False IsDate() ... False IsNothing() ... True IsNumeric(-12.345) ... True IsDate(-12.345) ... False IsNothing(-12.345) ... False IsNumeric(July 17, 2007) ... False IsDate(July 17, 2007) ... True IsNothing(July 17, 2007) ... False