Resolved How to display the win 10 calculator history?

LMCKC207

Member
Joined
Apr 9, 2020
Messages
17
Programming Experience
Beginner
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 circled one is what I'm trying to achieve but I can't make it to work. I also don't know if that's a label or a textbox that is just transparent?

Calculator 24_05_2020 5_59_24 AM.png



This is the code I'm using when to display the history. The user needs to click one of the operators.:
 Private Sub operation_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click, btnDivide.Click, btnAdd.Click, btnMinus.Click

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

        If input <> 0 Then

            btnEquals.PerformClick()
            expression = True
            operation = btnOperation.Text
            txtHistory.Text = input & " " & operation

        Else

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

        End If


    End Sub
 
If your intent is to display text then your first choice should be a Label. If you need to accept input too then obviously you need a TextBox. If you don't want to accept input but you want the user to be able to copy the text that is displayed then a TextBox with its ReadOnly property set to True is the way to go.

As for the history you're talking about, the logic seems fairly obvious to me. Each time the user enters an operator, the previous number and that operator are appended.
 
If your intent is to display text then your first choice should be a Label. If you need to accept input too then obviously you need a TextBox. If you don't want to accept input but you want the user to be able to copy the text that is displayed then a TextBox with its ReadOnly property set to True is the way to go.

As for the history you're talking about, the logic seems fairly obvious to me. Each time the user enters an operator, the previous number and that operator are appended.

Hi jmcilhinney,

yes that's exactly I think how it works but I don't know how to write it.
I'm using this code but it just doesnt do the work. I already tried everything that comes up in my head just to copy that history.
txtHistory.Text = numStr & " " & btnOperation.Text
 
Just apply a bit of logic. If you had a numeric variable X and you wanted to add Y to it, would you expect X = Y to work? I certainly hope not, yet that's exactly what you're doing in your current code.
 
I got the history working now. Below is my code.

code for the numbers 0-9:
 Private Sub btnNumbers_Click(sender As Object, e As EventArgs) Handles btn9.Click, btn8.Click, btn6.Click, btn5.Click, btn4.Click, btn3.Click, btn2.Click, btn1.Click, btn0.Click


        Dim btnNum As Button = CType(sender, Button)

        input = CDbl(btnNum.Text)

        If txtInput.Text = "0" Or flag = True Then

            txtInput.Text = ""
            txtInput.Text = btnNum.Text
            flag = False


        Else

            txtInput.Text = txtInput.Text & btnNum.Text

        End If


    End Sub



code I'm using for the operators:
    Private Sub btnSign(sender As Object, e As EventArgs) Handles btnMultiply.Click, btnMinus.Click, btnDivide.Click, btnAdd.Click

        Dim btnSigns As Button = CType(sender, Button)
        operation = btnSigns.Text


        If txtInput.Text <> 0 Then

                operation = btnSigns.Text
                txtHistory.Text = txtHistory.Text & " " & txtInput.Text & " " & btnSigns.Text
                flag = True

        Else

                operation = btnSigns.Text
                txtHistory.Text = txtHistory.Text & " " & txtInput.Text & " " & btnSigns.Text
                flag = True
            End If

    End Sub
 
Last edited:
But another problem arises. Should I make another thread for this?
All you have to do to answer that question is read the title of this thread. That's what this thread is about. Is that what you're asking about? The answer is "no", so it doesn't belong in this thread. One thread per topic and one topic per thread.
 
All you have to do to answer that question is read the title of this thread. That's what this thread is about. Is that what you're asking about? The answer is "no", so it doesn't belong in this thread. One thread per topic and one topic per thread.
got it
 
Back
Top