This is the simple program which will explain how to add two numbers in VB.NET. Adding two numbers is not complicated but you have to work in some basic programs. Here we created 3 text boxes. Two text box to enter number 1 and number 2 and 3rd text box to display the total. One button added, Onclick event of the button it displays the sum of number 1 and number 2 in the total text box.
This code is very simple and its created in Visual studio 2012. Kindly add the following tools in the form:
- Insert three labels and change its text property- Number 1, Number 2 and Total
- Name of the number 1 Text box – txtnum1
- Name of the number 2 Text box – txtnum2
- Name of the Total text box – txttotal
- Name of the button – btntotal
The two textboxes are txtnum1 and txtnum2 contains numbers. The val function converts string to number. The following code created in the btntotal click event:
Private Sub btntotal_Click(sender As Object, e As EventArgs) Handles btntotal.Click
txttotal.Text = Val(txtnum1.Text) + Val(txtnum2.Text)
After entering source code run your program and check its working properly or not.
Download this source code:
This video will explain how our source code works and how to create this simple example code: