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

0
75

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.
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2. With TextBox1
    3. If Not IsNumeric(.Text) And .Text <> vbNullString Then
    4. MsgBox("Sorry, only numbers allowed")
    5. .Text = ""
    6. Else
    7. With TextBox2
    8. If Not IsNumeric(.Text) And .Text <> vbNullString Then
    9. MsgBox("Sorry, only numbers allowed")
    10. .Text = ""
    11. Else
    12. MsgBox("The Average is " & (Val(TextBox1.Text) + Val(TextBox2.Text)) / 2)
    13. End If
    14. End With
    15. End If
    16. End WithEnd Sub
  • 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:

 

 

 

Facebook Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here