Three Textbox Calculator in Visual Basic .NET

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

This tutorial will show you how to make a calculator that calculates two textboxes automatically without any control.

Add three textboxes to the form. Add them in this order: put the first one on the left side, the second on the middle and the third one the right like the following picture:

Add two labels to the form and change their text property to + and = :

Double click on the first textbox "the one on the left" and adjust the code to the following code

Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles TextBox1.TextChanged
TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub

Double click on the second textbox "the middle one" and add the following code:

Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) _
 Handles TextBox2.TextChanged
	TextBox3.Text = Val(TextBox1.Text) + Val(TextBox2.Text)
End Sub

Run the program and the third textbox should show the total of the first textbox and the second one as soon you enter numbers in them.


Share This

Home | About | Contact | Privacy Policy

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