Question Calculator: don't know how to do it

Daloh

New member
Joined
Apr 14, 2014
Messages
1
Programming Experience
Beginner
Hi guys,

I'm new here and in VB.NET also, we can say I'm a noob xD

I recently started a Calculator and it's working more or less although I have to polish it a bit more. Now, I'm facing a problem and I have no clue how to solve it. I want that the numbers and operators I use, be displayed and not disapear until I click the "clear" button. I've trying around but I haven't find the solution.

Can anyone show me the way? I need some hints...

Greetings,

Here it goes the code I have until now.
@Admin: If something is wrong, feel free to edit/delete this post.
Public Class Form1
    Dim FirstNumber As Double
    Dim Operation As String
    Dim ClearField As Boolean = True
 
    Private Sub AddNumber(NewValue As String)
        If ClearField = True Then Viewer.Text = ""
        Viewer.Text &= NewValue
        ClearField = False
 
    End Sub
 
    'BUTTONS
    'Numbers
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        AddNumber("1")
 
    End Sub
 
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        AddNumber("2")
    End Sub
 
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        AddNumber("3")
    End Sub
 
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        AddNumber("4")
    End Sub
 
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        AddNumber("5")
    End Sub
 
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        AddNumber("6")
    End Sub
 
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        AddNumber("7")
    End Sub
 
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        AddNumber("8")
    End Sub
 
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        AddNumber("9")
    End Sub
 
    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Zero.Click
        AddNumber("0")
    End Sub
 
    'Buttons "," "del" "clear"
 
    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Dot.Click
        Viewer.Text = Viewer.Text + ","
    End Sub
 
    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Del.Click
        Viewer.Text = Viewer.Text.Remove(Viewer.Text.Length - 1, 1)
    End Sub
 
    Private Sub Clear_Click(sender As Object, e As EventArgs) Handles Clear.Click
        Viewer.Text = ""
    End Sub
 
    Private Sub Sum_Click(sender As Object, e As EventArgs) Handles Sum.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "SUM"
        Viewer.Text = ""
    End Sub
 
    Private Sub Minus_Click(sender As Object, e As EventArgs) Handles Minus.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "MINUS"
        Viewer.Text = ""
    End Sub
 
    Private Sub Multi_Click(sender As Object, e As EventArgs) Handles Multi.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "MULTI"
        Viewer.Text = ""
    End Sub
 
    Private Sub Div_Click(sender As Object, e As EventArgs) Handles Div.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "DIV"
        Viewer.Text = ""
    End Sub
 
    Private Sub Result_Click(sender As Object, e As EventArgs) Handles Result.Click
        Dim SecondNumber As Double
        Dim Result As Double
 
        SecondNumber = Val(Viewer.Text)
 
        'Fx
        If Operation = "SUM" Then
            Result = FirstNumber + SecondNumber
        End If
 
        If Operation = "MINUS" Then
            Result = FirstNumber - SecondNumber
        End If
 
        If Operation = "MULTI" Then
            Result = FirstNumber * SecondNumber
        End If
 
        If Operation = "DIV" Then
            Result = FirstNumber / SecondNumber
        End If
 
        Viewer.Text = Result
        ClearField = True
 
    End Sub
 
 
    Private Sub SalirToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles SalirToolStripMenuItem1.Click
        End
    End Sub
 
 
 
End Class
 
Last edited by a moderator:
It's not really clear what you mean. Can you describe what you're doing, what you want to see and what you actually see. Then we will know where in the code to look rather than having to work out what all that code with no comments does.
 
Hi guys,

I'm new here and in VB.NET also, we can say I'm a noob xD

I recently started a Calculator and it's working more or less although I have to polish it a bit more. Now, I'm facing a problem and I have no clue how to solve it. I want that the numbers and operators I use, be displayed and not disapear until I click the "clear" button. I've trying around but I haven't find the solution.

Can anyone show me the way? I need some hints...

Greetings,

Here it goes the code I have until now.
@Admin: If something is wrong, feel free to edit/delete this post.
Public Class Form1
    Dim FirstNumber As Double
    Dim Operation As String
    Dim ClearField As Boolean = True
 
    Private Sub AddNumber(NewValue As String)
        If ClearField = True Then Viewer.Text = ""
        Viewer.Text &= NewValue
        ClearField = False
 
    End Sub
 
    'BUTTONS
    'Numbers
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        AddNumber("1")
 
    End Sub
 
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        AddNumber("2")
    End Sub
 
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        AddNumber("3")
    End Sub
 
    Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
        AddNumber("4")
    End Sub
 
    Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
        AddNumber("5")
    End Sub
 
    Private Sub Button6_Click(sender As Object, e As EventArgs) Handles Button6.Click
        AddNumber("6")
    End Sub
 
    Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
        AddNumber("7")
    End Sub
 
    Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click
        AddNumber("8")
    End Sub
 
    Private Sub Button9_Click(sender As Object, e As EventArgs) Handles Button9.Click
        AddNumber("9")
    End Sub
 
    Private Sub Button15_Click(sender As Object, e As EventArgs) Handles Zero.Click
        AddNumber("0")
    End Sub
 
    'Buttons "," "del" "clear"
 
    Private Sub Button14_Click(sender As Object, e As EventArgs) Handles Dot.Click
        Viewer.Text = Viewer.Text + ","
    End Sub
 
    Private Sub Button17_Click(sender As Object, e As EventArgs) Handles Del.Click
        Viewer.Text = Viewer.Text.Remove(Viewer.Text.Length - 1, 1)
    End Sub
 
    Private Sub Clear_Click(sender As Object, e As EventArgs) Handles Clear.Click
        Viewer.Text = ""
    End Sub
 
    Private Sub Sum_Click(sender As Object, e As EventArgs) Handles Sum.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "SUM"
        Viewer.Text = ""
    End Sub
 
    Private Sub Minus_Click(sender As Object, e As EventArgs) Handles Minus.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "MINUS"
        Viewer.Text = ""
    End Sub
 
    Private Sub Multi_Click(sender As Object, e As EventArgs) Handles Multi.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "MULTI"
        Viewer.Text = ""
    End Sub
 
    Private Sub Div_Click(sender As Object, e As EventArgs) Handles Div.Click
        FirstNumber = Val(Viewer.Text)
        Operation = "DIV"
        Viewer.Text = ""
    End Sub
 
    Private Sub Result_Click(sender As Object, e As EventArgs) Handles Result.Click
        Dim SecondNumber As Double
        Dim Result As Double
 
        SecondNumber = Val(Viewer.Text)
 
        'Fx
        If Operation = "SUM" Then
            Result = FirstNumber + SecondNumber
        End If
 
        If Operation = "MINUS" Then
            Result = FirstNumber - SecondNumber
        End If
 
        If Operation = "MULTI" Then
            Result = FirstNumber * SecondNumber
        End If
 
        If Operation = "DIV" Then
            Result = FirstNumber / SecondNumber
        End If
 
        Viewer.Text = Result
        ClearField = True
 
    End Sub
 
 
    Private Sub SalirToolStripMenuItem1_Click(sender As Object, e As EventArgs) Handles SalirToolStripMenuItem1.Click
        End
    End Sub
 
 
 
End Class


try mine this works well

] Dim FirstNumber As Double    Dim SecondNumber As Double
    Dim Process As String
    Dim Answer As Double




    Private Sub ZeroButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ZeroButton.Click
        Textbox1.Text = Textbox1.Text & 0
    End Sub


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        DateLabel.Text = My.Computer.Clock.LocalTime.Date
    End Sub


    Private Sub OneButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OneButton.Click
        Textbox1.Text = Textbox1.Text & 1
    End Sub


    Private Sub TwoButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TwoButton.Click
        Textbox1.Text = Textbox1.Text & 2
    End Sub


    Private Sub ThreeButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ThreeButton.Click
        Textbox1.Text = Textbox1.Text & 3
    End Sub


    Private Sub FourButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FourButton.Click
        Textbox1.Text = Textbox1.Text & 4
    End Sub


    Private Sub FiveButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FiveButton.Click
        Textbox1.Text = Textbox1.Text & 5
    End Sub


    Private Sub SixButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SixButton.Click
        Textbox1.Text = Textbox1.Text & 6
    End Sub


    Private Sub SevenButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SevenButton.Click
        Textbox1.Text = Textbox1.Text & 7
    End Sub


    Private Sub EightButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EightButton.Click
        Textbox1.Text = Textbox1.Text & 8
    End Sub


    Private Sub NineButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles NineButton.Click
        Textbox1.Text = Textbox1.Text & 9
    End Sub


    Private Sub CancelButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CancelButton.Click
        TextBox1.Clear()
        PointButton.Enabled = True


    End Sub


    Private Sub PointButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PointButton.Click
        TextBox1.Text = TextBox1.Text & "."
        PointButton.Enabled = False
    End Sub


    Private Sub DevideButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DevideButton.Click
        If Textbox1.Text = "" Then
            MsgBox("Please input number", MsgBoxStyle.Information)
        Else


            FirstNumber = Val(Textbox1.Text)
            Process = "/"
            Textbox1.Text = ""
            PointButton.Enabled = True
        End If


    End Sub


    Private Sub MultiplyButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MultiplyButton.Click
        If Textbox1.Text = "" Then
            MsgBox("Please input number", MsgBoxStyle.Information)
        Else


            FirstNumber = Val(Textbox1.Text)
            Process = "x"
            Textbox1.Text = ""
            PointButton.Enabled = True
        End If
    End Sub


    Private Sub MinusButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MinusButton.Click
        If Textbox1.Text = "" Then
            MsgBox("Please input number", MsgBoxStyle.Information)
        Else


            FirstNumber = Val(Textbox1.Text)
            Process = "-"
            Textbox1.Text = ""
            PointButton.Enabled = True
        End If
    End Sub


    Private Sub PlusButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PlusButton.Click
        If Textbox1.Text = "" Then
            MsgBox("Please input number", MsgBoxStyle.Information)
        Else


            FirstNumber = Val(Textbox1.Text)
            Process = "+"
            Textbox1.Text = ""
            PointButton.Enabled = True
        End If
    End Sub


    Private Sub EqualsButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EqualsButton.Click
        SecondNumber = Val(TextBox1.Text)


        If Process = "/" Then
            Answer = FirstNumber / SecondNumber
            Textbox1.Text = Answer
        End If


        If Process = "+" Then
            Answer = FirstNumber + SecondNumber
            Textbox1.Text = Answer
        End If


        If Process = "x" Then
            Answer = FirstNumber * SecondNumber
            Textbox1.Text = Answer
        End If


        If Process = "-" Then
            Answer = FirstNumber - SecondNumber
            Textbox1.Text = Answer
        End If


        PointButton.Enabled = True
    End Sub
 
Last edited by a moderator:

Latest posts

Back
Top