Something along these lines will work:
Alterantively, since we aren't using the variable 'result' you can use this:Code:Private Sub btnCalculate1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate1.Click Dim valid As Boolean = True If Not EntryIsValid(Me.txtNumber1.Text) Then valid = valid And False End If If Not EntryIsValid(Me.txtNumber2.Text) Then valid = valid And False End If If valid then 'do what needs to be done if the entries are valid Else 'do what needs to be done if the entries were not numbers End If End Sub Private Function EntryIsValid(ByVal value As String) As Boolean Dim result As Single = 0 If Single.TryParse(value, result) Then Return True End If Return False End Function
Although, the intermediate code will make up a variable for you.
Code:Private Function EntryIsValid(ByVal value As String) As Boolean If Single.TryParse(value, Nothing) Then Return True End If Return False End Function




Reply With Quote