Click here to Skip to main content
15,665,444 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi I need some little help here. I'm trying to make a look-alike of win 10 calculator for my project but I can't understand the logic of the history (I don't know what it's called it just look like the history of what you do. The label that is just above the textbox and display all the calculation that you have made.)

What I have tried:

I'm using this code to display the performed calculation in that history (
again I don't know what to call it)

Private Sub operation_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click, btnMinus.Click, btnDivide.Click, btnAdd.Click

       Dim btnOperation As Guna.UI.WinForms.GunaButton = DirectCast(sender, Guna.UI.WinForms.GunaButton)

       If input <> 0 Then

           expression = True
           operation = btnOperation.Text
           txtHistory.Text = input & "if" & operation


           operation = btnOperation.Text
           input = Double.Parse(txtInput.Text)
           expression = True
           txtHistory.Text = input & "else" & operation

       End If

   End Sub

I'm passing my operation like add, multiply, divide,subtract to a single button.
the problem is I don't understand the logic how does the win 10 calculator display the previous calculations performed continuously?
Updated 24-May-20 2:55am
Richard MacCutchan 24-May-20 4:42am    
You need to create a string to hold the details. Each time a button is pressed on the calculator you add that character to the string. If the character is one of the operators then add a space in front and behind it. Otherwise just add numbers as they are typed.
lelouch_vi 2 24-May-20 5:37am    
Hi Richard MacCutchan,

thanks for the reply but honestly I don't know how to start it. I got your point which is very straightforward and clear but I don't where to start it. Should I use an array or list? Do I need to run a loop to display them?
Richard MacCutchan 24-May-20 5:49am    
It depends what you are trying to achieve. If you just want to show what the user is typing then a simple string will do it. If you want to be able to go back to a previous part of the sum then you need to capture the actual values and operators in a form the allows you to recreate a part of the calculation. There are plenty of examples that Google will find for you.

1 solution

The source code of the Windows calculator can be found here: GitHub - microsoft/calculator: Windows Calculator: A simple yet powerful calculator that ships with Windows[^]
Maybe you can find out how it works by browsing the source code.
Also read the information in the Docs folder: calculator/ at master · microsoft/calculator · GitHub[^]
Share this answer
Maciej Los 25-May-20 5:57am    

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900