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

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:

What is Visual Basic for Windows?

Microsoft’s Visual Basic is an object-oriented development environment and programming language. Users can change the design and behavior of their apps using a graphical user interface that allows them to edit code by dragging and dropping objects. The object-oriented language is based on BASIC and is recommended for novices who are starting to code.

What is Visual Basic’s purpose?

The third-generation programming language was created to aid developers in the creation of Windows applications. It has a programming environment that allows programmers to write code in.exe or executable files. They can also utilize it to create in-house front-end solutions for interacting with huge databases. Because the language allows for continuing changes, you can keep coding and revising your work as needed.

  • 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 Comment