Creating a calculator in visual basic

Assignment Help Software Engineering
Reference no: EM13994674

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

'''<summary>

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

''' </summary>

''' <param name ="strOperation">the math operation to perform +,-,*,/ or clear

''' </param>

''' <remarks><</remarks>

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

Reference no: EM13994674

Questions Cloud

Foreign exchange rates in the wall street journal : In looking at the foreign exchange rates in the Wall Street Journal you notice the dollar-euro spot rate is 1.085€/$ and the six-month forward rate is 1.098€/$. Does this imply that the US dollar is expected to appreciate or depreciate?
Consist of a series of phases : The software life cycle can be said to consist of a series of phases. The classical model is referred to as the waterfall model. Which phase may be defined as "The concept is explored and refined, and the client's requirements are elicited?"
What is the largest resistance you can obtain : Consider connecting three resistors of resistances 31 Ω, 49 Ω, and 695 Ω together. What is the largest resistance you can obtain in Ω? What is the smallest resistance you can obtain in Ω?
Would an increase in european wealth : Would an increase in European wealth, all other factors held constant, cause the dollar to depreciate or appreciate in the foreign exchange market?
Creating a calculator in visual basic : 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
Develop a plan for an event : Develop a plan for an event (e.g., golf tournament; gala ball; annual meeting; or a series of lectures, workshops, or seminars where a fee is charged for attendance or participation) for your organization.
Economic growth and environmental degradation : Historically there has been a close correlation between economic growth and environmental degradation. Is it possible to be sustainable and profitable?
Find the equivalent resistance between point a and b : Find the equivalent resistance between point a and b. If a voltage of 37.9 V is applied between points a and b, find the current in each resistor.
Companys internal corporate marketed department : Your local fast food chain with two dozen stores uses the company's internal corporate marketed department to produce signage, print ads, in-store displays, and so forth. When placing an order, store managers are assessed a chargeback (transfer price..

Reviews

Write a Review

Software Engineering Questions & Answers

  Explain the various types of actors in a use case

Define the term ‘use case' and explain the various types of actors in a Use Case. Explain the difference between the > and > relationships in use case diagrams

  Describe in a one to two 1-2 page narrative a use case

describe in a one to two 1-2 page narrative a use case complete with typical and alternate courses that documents the

  As the lead software engineer for a medium-sized hospital

as the lead software engineer for a medium-sized hospital you have been asked to spearhead an effort to improve the

  What is hidden can be changed without risk

What is hidden can be changed without risk and define the terms in each law and explain the law clearly and thoroughly. Illustrate your explanation with practical examples

  Why is the definition of the system logistics and

answer the module review questions listed below. these questions were chosen to demonstrate your understanding and help

  1 what is the role of the project manager why is

1. what is the role of the project manager? why is leadership so important for project managers?2. discuss the

  Compare the evolutionary design process to waterfall method

Compare the evolutionary design process to the waterfall method. Why do you think some companies move to the newer design methods (evolutionary) and some remain with the older methods (waterfall)

  Bridge between user requirements and the software code

Professionals working in software industry often refer "software design" as "building the bridge between user requirements and the software code"

  Advantage of managing input and output

Explain why a DMA channel would or would not be useful in a computer without an interrupt-based I/O system.

  Preparing a short video clip

Create a short video clip on some topic from your chosen multimedia assignment. Do the same for a short 3D animation using Blender on a different topic.

  Compare agile and waterfall models of managing a project

Compare and contrast agile and Waterfall models of managing a project in the context of building an e-Commerce Website

  How the sequential and additive composition adaptors differ

how the sequential and additive composition adaptors differ

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd