How to Get the Average of Two Numbers in VB.Net

0
441

This tutorial is all about How to Get the Average of Two Numbers in VB.Net. With this tutorial you can Get the Average of Two Numbers in VB.Net easily. So let’s get started:

  • First is open the Visual Basic, Select File on the menu, then click New and create a new project.

  • Then a New Project Dialog will appear. You can rename your project, depending on what you like to name it. After that click OK

  • Design your form like this just like what I’ve shown you below.
    Add a Label, 2 Textbox, and a Button.
  • After Designing your form, Add this code to the button.
    [vbnet]
    Private Sub Button1_Click(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 WithEnd Sub
    [/vbnet]
  • Finally, Click F5 to run Program.
    Output:

If you have any comments or suggestion about on How to Get the Average of Two Numbers in VB.Net, Please Feel Free to contact our webpage.

Download How to Get the Average of Two Numbers in VB.Net Code Here

Other articles you might read also:

 

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.