Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Designing the Form Let's design the form first. What does a calculator need? Well numbers, for one. A display area for the result. A plus

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
Designing the Form Let's design the form first. What does a calculator need? Well numbers, for one. A display area for the result. A plus sign button, an equals sign button, and a clear the display button. Here's how our calculator is going to work. We'll have 10 button for the numbers 0 to 9 . When a button is clicked its value will be transferred to a display area, which will be a Textbox. Once a number is transferred to the Textbox we can click on the Plus button. Then we need to click back on another number. To get the answer, we'll click on the equals sign. To clear the display, we'll have a Clear button. If you haven't already, create a new project. Save it as Calculator. To your new form, first add ten Buttons (You can add one, then copy and paste the rest). The Buttons should have the following Properties: Name: btn Plus a Number (btnOne, btnTwo, btnThree, etc) Text: A number from 0 to 9 . A different one for each button, obviously Font: MS Sans Serif, Bold, 14 Next, add a Textbox. Set the following properties for the Textbox: Textbox Name: txtDisplay Font: MS Sans Serif, Bold, 14 Text: Erase the default, Textbox1, and leave it blank Three more buttons need to be added Plus Button Name: btnPlus Font: MS Sans Serif, Bold, 14 Text: + Equals Button Name: btnEquals Font MS Sans Serif, Bold, 14 Text: = Clear Button Name: btnClear Font MS Sans Serif, Bold, 14 Text: Clear When your form design is finished, it might look something like this: So if you wanted to add 5+9, you would click first on the 5 . A 5 would appear in the textbox. Then you would click the + symbol. The 5 would disappear from the textbox. Next, click on the 9 . The number 9 would appear in the textbox. Finally, click on the = symbol. The 9 would disappear from the textbox, and the answer to our sum would replace it. We would then click the Clear button to clear the display. In the next section, we'll make a start on the VB NET code for the all those buttons. The 0 to 9 Buttons The Buttons with the Text 0 to 9 only need to do one thing when the button is clicked - have their Text Properties transferred to the Textbox. So double click the 0 Button and enter the following code: 0 Private Sub btnZero_Click(sender As Object, e As EventArgs) _Handles binZero. Click txtDisplay. Text = txtDisplay. Text \& btnZero.TextbtnZero.Text End Sub This code will transfer the Text Property of a Button called btnZero to the Text Property of a Textbox called txtDisplay. Run your programme and try it out. When the programme is running, click the 0 button to see that it transfers the Text on the Button to the textbox. Please write a CODE for another button example for I. 1 Private Sub btnOne_Click(sender As Object, e As EventArgs) - Handles btnOne. Click txtDisplay. Text = txtDisplay. Text \& btnOne. TextbtnOne. Text End Sub Followed by 2 until 9 . BELOW IS THE COMPLETE CODE FOR THE CALCULATOR Public Class Form! Inherits System. Windows. Forms. Form 'VARIABLES AT THE TOP OF THE CODING WINDOW Dim totall As Integer Dim total2 As Integer 'CODE FOR THE NUMBER BUTTONS Private Sub benOne_Click(ByVal sender As System.Object, ByVal e As System. Eventirgs) Handles btnOne Click triDisplay: Text = futDisplay. Tert \& benOne. Text End Sub Private Sub bviZero_Click(ByVal sender As System. Obiect, ByVal e As System.EventArgs) Handles benZero. Click tatDisplay:Text = tatDisplay. Text \& benZero. Text End Sub Private Sab brnTuo_Click(ByVal sender As System. Objiect. ByVal e. As System. EventArgs) Handles benTwa. Click txtDisplay. Text = trtDisplay: Ted \& btn Two. Text End Sub Private Sub brnThree_Click(ByVal sender As System. Object. ByVal e As System. EventArgs) Handles ben Three. Click txtDisplay: Text = rxtDisplay: Text & btn Three. Text End Sub Private Sub brnFour_ClicklByVal sender As System.Object, ByVal e.As System. EventArgs) Handles benFour. Click txtDisplay: Text = trtDisplay: Text \& benFour. Text End Sub Private Sub broFive_Click(ByVal sender As System.Object, ByVal e As System. EventAngs) Handles benFive.Click tuDisplay: Text = tutbisplay. Text of btnFive Tert End Sub Private Sub brnSix_Click/ByVal sender As System. Object, ByVal e.As System. EventArys) Handles benSix. Click txt Display Text =tt Display. Text \& btnSix. Teat End Sub Private Sub benSoven_Click(ByVal sender As System_Object, ByVal e As System. EventArys) Handles bunSeven. Click txtDisplay: Text = tutDisplay. Text \& benSeven Teut End Sub Private Sub brnEight_Click(ByVal sender As. System. Object, Bylal e As System. Eventirgs) Handles benEight Click txtDisplay: Text = tviDisplay. Text \& benEight. Text End Sub 12:25 moodle1.du.edu.om Private Sab binkight_Click(ByVal sender As System, Object. ByVal e As System. EventArgs) Handles borEight. Click truDisplay: Fat= suDisplay. Text a berFight. Text End Sub Private Sab bin.Nine_Click/ByVal sender As System. Obyinct. ByVal e As System. Eventargs) Handles berNine. Click trtDisplay: Text = triDisplay. Text & benNine, Tert End Sub CODE FOR THE PLUS BUTTON Private Sab cmdPlas Click(By Ial sender As System. Object. ByVal e As System. EventArgs) Handles condPlus. Click totall = totall + ValiatDisplay. Tevi txtDisplay: Clearo End Sab ' CODE FOR THE EQUALS BUTTON Private Sub codEquals_Click/Bylal sender As System, Object, By Val e As System. EventAgs) Handles cmdEquals. Click total2 = totall + Val(txtDisplay: Text ) traDisplay: Teat = total2 totall = End Sab CODE FOR THE CLEAR BUTTON Private Sab cudClear_Click/ByVal sender As System, Obyect, ByVal e As System. Event,Angs) Handles cudicleariclick txiDisplay:Cleard End Sub End Class

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting For Inventory

Authors: Steven M. Bragg

4th Edition

1642210714, 9781642210712

More Books

Students also viewed these Accounting questions