Hello,
- Never use Val, that is not the .NET way but the VB6 way and best to stay away from VB6 coding
- Always assume a value is not a number (NaN)
- If this was JavaScript we would use isNaN e.g. if (Number.isNaN(someObject.someValue)) ...
Simple example (the Integer.TryParse could also be Double.TryParse, Decimal.TryParse). You should add an "Else" to the "If" statement to inform the user one of the numbers is not a number.
Public Class Form1
Private Sub CalulateButton_Click(sender As Object, e As EventArgs) Handles CalulateButton.Click
Dim value1 As Integer
Dim value2 As Integer
If Integer.TryParse(TextBox1.Text, value1) AndAlso Integer.TryParse(TextBox2.Text, value2) Then
Label1.Text = $"{Math.Round(value1) / value2}"
End If
End Sub
End Class