Imports System.Globalization
Module ByteConversion2
Public Sub Main()
Dim byteString As String
Dim styles As NumberStyles
byteString = "100.1"
styles = NumberStyles.Integer Or NumberStyles.AllowDecimalPoint
CallTryParse(byteString, styles)
End Sub
Private Sub CallTryParse(stringToConvert As String, styles As NumberStyles)
Dim byteValue As Byte
Dim result As Boolean = Byte.TryParse(stringToConvert, styles, Nothing, byteValue)
If result Then
Console.WriteLine("Converted '{0}' to {1}",stringToConvert, byteValue)
Else
If stringToConvert Is Nothing Then stringToConvert = ""
Console.WriteLine("Attempted conversion of '{0}' failed.",stringToConvert.ToString())
End If
End Sub
End Module