Designing a Calculator in Visual Basic 2013 Part 2

WhatsAppTwitterGoogle+Google GmailShare

In our previous post, we have shown you the interface of the calculator and the code that can display numbers on the panel. In this article, we will delve into the code that makes calculator in visual basic 2013 works.

Let’s review the first part of code that displays numbers on the display panel when he user click on the number buttons.

Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn0.Click, Btn1.Click, Btn2.Click, Btn3.Click,
Btn4.Click, Btn5.Click, Btn6.Click, Btn7.Click, Btn8.Click, Btn9.Click

If LblPanel.Text = “0” Then LblPanel.Text = “”
LblPanel.Text += sender.text

End Sub

To display numbers on the code, we just need to write one block of code for all the number buttons instead of one block of code for each and every button. The method is by using the sender object and by placing click event for all the buttons after the Handles keyword, separated by commas.

The meaning of sender As Object is the object that responses when the user clicks on a particular button. For example, if the user clicks on Btn2 number button, the sender is Btn2. The action is to display the text of the sender on the display panel, in this case it is 2 if the text on the display button is 0, otherwise the digit 2 will be placed in front of the previous digit.

We shall continue our discussion in next article….

WhatsAppTwitterGoogle+Google GmailShare

Designing a Calculator in Visual Basic 2013 Part 1

WhatsAppTwitterGoogle+Google GmailShare

We have shown you how to design a calculator in Visual Basic 6. Now we wish to demonstrate how to create a calculator in Visual basic 2013. First of all, design the interface of the calculator as shown below;
calculatorFirst, Insert a label to be used as display panel for the calculator. Next, insert ten number buttons and change the text from 0 to 9. Finally, insert the buttons to be used as arithmetic operators and other functions such as backspace.

Now, we shall show you how to display the numbers on the display panel. Write the following code to response to clicks from the user on the number buttons. Write the code by double clicking on any number button, here we use the button with number 1.

Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn0.Click, Btn1.Click, Btn2.Click, Btn3.Click,
Btn4.Click, Btn5.Click, Btn6.Click, Btn7.Click, Btn8.Click, Btn9.Click

If LblPanel.Text = “0” Then LblPanel.Text = “”
LblPanel.Text += sender.text

End Sub

This code with display numbers on the display panel.

We will show you how to write other codes in next article.

 

 

WhatsAppTwitterGoogle+Google GmailShare