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.
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: