SIMPLE CALCULATOR PROGRAM

SIMPLE CALCULATOR PROGRAM

This tutorial is continuation from visual basic programming part 1

In this tutorial we are going to create a simple calculator program.

The interface for the program will be as shown below

calculator interface
calculator interface

change the text properties as shown above and their names as

btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn0, btnequals, btnplus, btnminus, btnmultiply, btndivide, btnclear

Explanation

when a button is clicked the text in it will be displayed on the textbox1.

The text in the textbox1 must be maintained for the next click.

Double click btn1 to open the coding window and enter the code below (the one in red)

Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click
TextBox1.Text = TextBox1.Text & btn1.Text
End Sub

Now run the application and click the btn1 and the application runs.

Note we are assigning textbox1 what is in it(textbox1) and the text in btn1 which is 1.



CODING THE OTHER BUTTONS

The code for the other buttons is the same only changing btn1 to btn2 and so on up to btn0.

Double click each of them and enter their codes.

run the application again ant try clicking each button.

a sneak preview of a portion of the coding window is shown below.

calculator coding window 1
calculator coding window 1

In the next tutorial we are going to code the plus(+) button and equals button to work for the addition.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *