Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Software Engineering Expert

Creating a calculator in Visual Basic,the instructions given to me by the professor and type the code in the order 

Option Explicit On

Option Strict On

Imports System.Math

 

PublicClassForm1

'declare the golbal variables here

Dim dblResult AsDouble'contains the result of a calculation

 

PrivateSub btnPower_Click(sender AsObject, e AsEventArgs) Handles btnPower.Click

'clear the values of all variables

        resetCalculator()

        dblResult = 0

Me.lblResult.Text = "0"

EndSub

 

PrivateSub Form1_Load(sender AsObject, e AsEventArgs) HandlesMyBase.Load

'clear the values of all variables

PrivateSub resetCalculator()

Me.lblResult.Text = "0"

        dblResult = 0

        strLastMathOperator = "Clear"

        blnStartNewNumber = True

        dblCurrentNumber = 0

EndSub

 

PrivateSub buildNumber() (ByVal strNumber As String)

        lblResult.Text = lblResult.Text & strNumber

        dblCurrentNumber = Convert.ToDouble(lblResult.Text)

'should we start a new number or add to an existing number?

If blnStartNewNumber Then

 

Else

'append to the current number

            lblResult.Text = lblResultResult.Text & strNumber

EndIf

        blnStartNewNumber = False

EndSub

    buildNumber ("2")

    lblResult.Text = lblResult.Text & strNumber

    dblCurrentNumber = Convert.ToDouble(lblResult.Text)

Me.lblResult.Text = ""

 

PrivateSub btn0_Click(sender AsObject, e AsEventArgs) Handles btn0.Click

        buildNumber("0")

EndSub

 

PrivateSub btn1_Click(sender AsObject, e AsEventArgs) Handles btn1.Click

        buildNumber("1")

EndSub

 

PrivateSub btn2_Click(sender AsObject, e AsEventArgs) Handles btn2.Click

        buildNumber("2")

EndSub

 

PrivateSub btn3_Click(sender AsObject, e AsEventArgs) Handles btn3.Click

        buildNumber("3")

EndSub

 

PrivateSub btn4_Click(sender AsObject, e AsEventArgs) Handles btn4.Click

        buildNumber("4")

EndSub

 

PrivateSub btn5_Click(sender AsObject, e AsEventArgs) Handles btn5.Click

        buildNumber("5")

EndSub

 

PrivateSub btn6_Click(sender AsObject, e AsEventArgs) Handles btn6.Click

        buildNumber("6")

EndSub

 

PrivateSub btn7_Click(sender AsObject, e AsEventArgs) Handles btn7.Click

        buildNumber("7")

EndSub

 

PrivateSub btn8_Click(sender AsObject, e AsEventArgs) Handles btn8.Click

        buildNumber("8")

EndSub

 

PrivateSub btn9_Click(sender AsObject, e AsEventArgs) Handles btn9.Click

        buildNumber("9")

EndSub

 

PrivateSub btnSQRT_Click(sender AsObject, e AsEventArgs) Handles btnSQRT.Click

        dblCurrentNumber = Sqrt(dblCurrentNumber)

Me.lblResult.Text = Str(dblCurrentNumber)

EndSub

 

PrivateSub btnPercent_Click(sender AsObject, e AsEventArgs) Handles btnPercent.Click

Me.lblResult.Text = Str(dblCurrentNumber / 100)

        dblCurrentNumber = dblCurrentNumber / 100

        blnStartNewNumber = True

EndSub

 

PrivateSub btnPlusMinus_Click(sender AsObject, e AsEventArgs) Handles btnPlusMinus.Click

        dblCurrentNmber = dblCurrentNumber * (-1)

Me.lblResult.Text = dblCurrentNumber.ToString()

EndSub

'''

'''Applies the last operator to result using current number

'''

''' the math operation to perform +,-,*,/ or clear

'''

''' <

PrivateSub handleOperator(ByVal strOperation AsString)

        handleOperator("Add")

PrivateSub handleOperator(ByVal strOperation AsString)

        strLastMathOperator = strOperation

EndSub

 

SelectCase strLastMathOperator.ToUpper

Case "ADD"

                dblResult = dblResult + dblCurrentNumber

Case "SUBTRACT"

                dblResult = dblResult - dblCurrentNumber

Case "MULTIPLY"

                dblResult = dblResult * dblCurrentNumber

Case "DIVIDE"

                dblResult = dblResult / dblCurrentNumber

CaseElse

             dblResult = dblCurrentNumber

EndSelect

 

    dblCurrentNumber = dblResult

Me.lblResult.Text = dblCurrentNumber.ToString

Me.blnStartNewNumber = True

    btnDecimal.Enabled = True

 

PrivateSub btnDecimal_Click(sender AsObject, e AsEventArgs) Handles btnDecimal.Click

        buildNumber(".")

If blnStartNewNumber Then

            buildNumber("0.")

Else

            buildNumber(".")

EndIf

        btnDecimal.Enabled = False

EndSub

 

PrivateSub btnMemoryAdd_Click(sender AsObject, e AsEventArgs) Handles btnMemoryAdd.Click

        dblMemory = dblMemory + Convert.ToDouble(lblResult.Text)

EndSub

 

PrivateSub btnMemoryClear_Click(sender AsObject, e AsEventArgs) Handles btnMemoryClear.Click

        dblMemory = 0

EndSub

 

PrivateSub btnMemoryRecall_Click(sender AsObject, e AsEventArgs) Handles btnMemoryRecall.Click

        lblResult.Text = dblMemory.ToString

        dblCurrentNumber = dblMemory

EndSub

 

PrivateSub btnMemorySubtract_Click(sender AsObject, e AsEventArgs) Handles btnMemorySubtract.Click

        dblMemory = dblMemory - Convert.ToDouble(lblResult.Text)

EndSub

 

EndClass

Software Engineering, Computer Science

  • Category:- Software Engineering
  • Reference No.:- M91703514

Have any Question?


Related Questions in Software Engineering

Write review on this article with apa formatalthough

Write review on this article with APA format. Although computer crimes are being seen in our society more and more each day, it is still difficult to prosecute people who commit these crimes mainly because everything is ...

Research projectin the course we have covered various

RESEARCH PROJECT In the course, we have covered various security and privacy issues that arise in the cyberspace field. We have learned to identify these risks and have discussed the current approaches and developments f ...

Address the following integrating biblical perspectives

Address the following, integrating biblical perspectives where appropriate: Define a hate crime and describe how white supremacist groups use the Internet to spread their message of hate. Explain why hate crime legislati ...

Write reply to this article with references with apa

Write reply to this article with references with APA bibliography. Hate Crimes Over the past couple of years, hate crimes have been on the rise in America's largest cities. Studies show that there were sharp spikes in th ...

Reply to this article with apa referencehate crimes

Reply to this article with APA reference. Hate crimes According to Merriam-Webster, hate crime is any of various crimes (such as assault or defacement of property) when motivated by hostility to the victim as a member of ...

Instructions - onion routingin this assignment you will

INSTRUCTIONS - ONION ROUTING In this assignment, you will answer the following questions related to Onion Routing and Tor. 1. Describe the infrastructure of Onion Routing and explain how it works for providing anonymity ...

Write review on this article with apa formatgovernment

Write review on this article with APA format. Government surveillance is a major issue in the United States and globally. Surveillance refers to any collection and processing of personal data, whether, identifiable or no ...

Assignment part 1objectives to learn to identify the

Assignment Part 1 Objectives: To learn to identify the relevant use cases for a given application, describe the use cases and develop an object-oriented domain model. Problem Statement - Standing Orders Management System ...

Overviewyou are required to modify and logically extend

Overview You are required to modify and logically extend the functionality of a provided code base to implement a game. This requires you to modify the code base as well as create documentation and implement various user ...

Proposaldesign of an efficient gps tracking system tag for

Proposal Design of an efficient GPS Tracking System (tag) for monitoring small species IMPLEMENTING EMBEDDED SYSTEMS USING SYSML Task Using PapyrusSysML Software (Downloadable online - Evaluation Copy- Latest Version) Mo ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As