Module ByteConversion
Public Sub Main()
Dim byteString As String = Nothing
byteString = "100.1"
CallTryParse(byteString)
byteString = "0x1F"
CallTryParse(byteString)
End Sub
Private Sub CallTryParse(stringToConvert As String)
Dim byteValue As Byte
Dim result As Boolean = Byte.TryParse(stringToConvert, 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