Validate numbers then average out scores: - Visual Basic .NET

Tags: VB.NET, VB 2008, VB 2010, VB 2012, VB 2013

For this tutorial add 2 textboxes, 2 labels and one button
Validate numbers then average out scores:- vb.net
The application also will validate inputs:
Validate numbers- vb.net
Here is the code for the Average button click event:
Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles Button1.Click
        With TextBox1
            If Not IsNumeric(.Text) And .Text <> vbNullString Then
                MsgBox("Sorry, only numbers allowed")
                .Text = ""
            Else
                With TextBox2
                    If Not IsNumeric(.Text) And .Text <> vbNullString Then
                        MsgBox("Sorry, only numbers allowed")
                        .Text = ""
                    Else
                        MsgBox("The Average is " & (Val(TextBox1.Text) + Val(TextBox2.Text)) / 2)
                    End If
                End With
            End If
        End With
End Sub


Share This

Home | About | Contact | Privacy Policy

Copyright visual-basic-tutorials.com 2017 - All Rights Reserved.