Imports System.Globalization
Module ParseInt32
Public Sub Main()
Convert("999.9", NumberStyles.AllowDecimalPoint)
Convert(" $1,999,999.42", NumberStyles.AllowCurrencySymbol Or NumberStyles.Number)
Convert("999E06", NumberStyles.AllowExponent)
Convert("-1,999,999", NumberStyles.AllowThousands)
Convert("(1,999,999)", NumberStyles.AllowThousands Or NumberStyles.AllowParentheses)
End Sub
Private Sub Convert(value As String, style As NumberStyles)
Try
Dim number As Integer = Int32.Parse(value, style)
Console.WriteLine("Converted '{0}' to {1}.", value, number)
Catch e As FormatException
Console.WriteLine("Unable to convert '{0}'.", value)
Catch e As OverflowException
Console.WriteLine("'{0}' is out of range of the Int32 type.", value)
End Try
End Sub
End Module