Skip to content

Commit

Permalink
add answer history and minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
NattyXO committed Jan 5, 2024
1 parent 53edf58 commit 6c8eeb6
Show file tree
Hide file tree
Showing 22 changed files with 265 additions and 69 deletions.
120 changes: 77 additions & 43 deletions scientific calc/Form1.Designer.vb

Large diffs are not rendered by default.

186 changes: 174 additions & 12 deletions scientific calc/Form1.vb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
'Code for extend form
Me.Height = 411
Me.Width = 587
btnEqual.Width = 200
txtAnswer.Width = 403
txtAnswer.Width = 334
End Sub

Private Sub UnitConversionToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles UnitConversionToolStripMenuItem.Click
'Code for extend form
Me.Height = 411
Me.Width = 846
btnEqual.Width = 200
txtAnswer.Width = 403
txtAnswer.Width = 334
End Sub

Private Sub EditToolStripMenuItem_Click(sender As Object, e As EventArgs)
Expand All @@ -35,10 +33,11 @@
'Code for extend form
Me.Height = 411
Me.Width = 310
btnEqual.Width = 131
txtAnswer.Width = 267
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.KeyPreview = True ' Enable key events for the form

Me.Height = 411
Me.Width = 310
btnEqual.Width = 131
Expand Down Expand Up @@ -278,10 +277,17 @@
End Sub

Private Sub btnEqual_Click(sender As Object, e As EventArgs) Handles btnEqual.Click

lblTop.Visible = True
Dim result As Double = Calculate(txtAnswer.Text)
If Not Double.IsNaN(result) Then
lblTop.Text = result.ToString() ' Set the result to the top label
' Add the result to the TreeView
Dim newNode As New TreeNode(result.ToString())
lstAnswer.Nodes.Add(newNode)

' Set the result to the top label
lblTop.Text = result.ToString()
lblTop.Visible = True
Else
' Optionally handle invalid expressions or errors here
End If
Expand All @@ -295,6 +301,12 @@
End Sub

Private Sub btnSquareRoot_Click(sender As Object, e As EventArgs) Handles btnSquareRoot.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
' Check if the input is empty or not a valid number
If String.IsNullOrWhiteSpace(txtAnswer.Text) Then
MessageBox.Show("Please enter a valid number to calculate Square.")
Expand All @@ -315,9 +327,10 @@


Private Sub NumberButton_Click(sender As Object, e As EventArgs) Handles btnInput1.Click, btnInput2.Click, btnInput9.Click, btnInput8.Click, btnInput7.Click, btnInput6.Click, btnInput5.Click, btnInput4.Click, btnInput3.Click, btnInput0.Click
If txtAnswer.Text = "∞" Then
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Then
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
' Code for button 1 to 9, 0
Expand Down Expand Up @@ -348,6 +361,12 @@
End Function

Private Sub OperationButton_Click(sender As Object, e As EventArgs) Handles btnAddition.Click, btnMultiplication.Click, btnModules.Click, btnMinus.Click, btnDivision.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
' Store the operator as the last input
lastInput = DirectCast(sender, Button).Text
dotUsed = False
Expand All @@ -356,6 +375,12 @@
txtAnswer.Text &= $" {button.Text} "
End Sub
Private Sub btnPi_Click(sender As Object, e As EventArgs) Handles btnPi.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
If Not txtAnswer.Text.Contains(Math.PI.ToString()) Then
' Append Pi to txtAnswer
txtAnswer.Text &= Math.PI.ToString()
Expand All @@ -370,6 +395,12 @@


Private Sub btnEuler_Click(sender As Object, e As EventArgs) Handles btnEuler.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
If Not txtAnswer.Text.Contains(Math.E.ToString()) Then
' Append Pi to txtAnswer
txtAnswer.Text &= Math.E.ToString()
Expand All @@ -386,10 +417,22 @@


Private Sub btnLeftBracket_Click(sender As Object, e As EventArgs) Handles btnLeftBracket.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
txtAnswer.Text &= "("
End Sub

Private Sub btnRightBracket_Click(sender As Object, e As EventArgs) Handles btnRightBracket.Click
txtAnswer.Focus()
If txtAnswer.Text = "∞" Or txtAnswer.Text = "∞ " Then
txtAnswer.Text = ""
ElseIf txtAnswer.Text = "NaN" Or txtAnswer.Text = "NaN " Then
txtAnswer.Text = ""
End If
txtAnswer.Text &= ")"
End Sub

Expand Down Expand Up @@ -585,15 +628,134 @@ Version 1.0.3(Official Build)")
End Sub

Private Sub KeyboardShortcutReferenceToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles KeyboardShortcutReferenceToolStripMenuItem.Click
MessageBox.Show("You Can type from the keyboard, like 0–9 and % * / + - ( )" & Environment.NewLine & "Also, you can use the Enter key to perform a calculation.")

Dim url As String = "https://github.com/NattyXO/Scientific-calculator/blob/main/Shortcut.md"

' Open the URL in the default browser
Try
Process.Start(url)
Catch ex As Exception
' Handle any potential exceptions if the URL cannot be opened
MessageBox.Show("Failed to open URL: " & ex.Message)
End Try
End Sub


Private Sub Form1_KeyDown(sender As Object, e As KeyEventArgs) Handles MyBase.KeyDown
'MessageBox.Show($"You pressed key: {e.KeyCode}", "Key Pressed")

' Check if the Enter key is pressed
If e.KeyCode = Keys.Enter Then
' Call the logic you want to perform when Enter is pressed (similar to btnEqual click)
If e.KeyCode = Keys.Space Then
btnEqual.PerformClick()
End If
ElseIf e.KeyCode = Keys.NumPad0 Then
btnInput0.PerformClick()
ElseIf e.KeyCode = Keys.NumPad1 Then
btnInput1.PerformClick()
ElseIf e.KeyCode = Keys.NumPad2 Then
btnInput2.PerformClick()
ElseIf e.KeyCode = Keys.NumPad3 Then
btnInput3.PerformClick()
ElseIf e.KeyCode = Keys.NumPad4 Then
btnInput4.PerformClick()
ElseIf e.KeyCode = Keys.NumPad5 Then
btnInput5.PerformClick()
ElseIf e.KeyCode = Keys.NumPad6 Then
btnInput6.PerformClick()
ElseIf e.KeyCode = Keys.NumPad7 Then
btnInput7.PerformClick()
ElseIf e.KeyCode = Keys.NumPad8 Then
btnInput8.PerformClick()
ElseIf e.KeyCode = Keys.NumPad9 Then
btnInput9.PerformClick()
ElseIf e.KeyCode = Keys.Add Then ' "+" key
btnAddition.PerformClick()
ElseIf e.KeyCode = Keys.Subtract Then ' "-" key
btnMinus.PerformClick()
ElseIf e.KeyCode = Keys.Multiply Then ' "*" key
btnMultiplication.PerformClick()
ElseIf e.KeyCode = Keys.Divide Then ' "/" key
btnDivision.PerformClick()
ElseIf e.KeyCode = Keys.OemPeriod Then ' "." key
btnDot.PerformClick()
ElseIf e.KeyCode = Keys.Decimal Then ' "." key
btnDot.PerformClick()
ElseIf e.KeyCode = Keys.OemMinus Then ' "-" key
btnMinus.PerformClick()
ElseIf e.KeyCode = Keys.Oemplus Then ' "+" key
btnAddition.PerformClick()
' Check if Ctrl+C is pressed and a node is selected
ElseIf e.KeyCode = Keys.C AndAlso e.Control AndAlso lstAnswer.SelectedNode IsNot Nothing Then
' Copy the selected node's text to the clipboard
Clipboard.SetText(lstAnswer.SelectedNode.Text)

ElseIf e.KeyCode = Keys.Back Then ' "back" key
btnBack.PerformClick()
ElseIf e.KeyCode = Keys.C Then ' "clear" key
btnClear.PerformClick()
ElseIf e.KeyCode = Keys.E Then ' "Euler" key
btnEuler.PerformClick()
ElseIf e.KeyCode = Keys.P Then ' "P" key
btnPi.PerformClick()
ElseIf e.KeyCode = Keys.OemQuestion AndAlso e.Shift Then
' This handles the "/" character using Shift + ?
btnDivision.PerformClick() ' Triggers the left parenthesis button click
ElseIf e.KeyCode = Keys.D5 AndAlso e.Shift Then
' This handles the "%" character using Shift + 9
btnModules.PerformClick()
ElseIf e.KeyCode = Keys.D9 AndAlso e.Shift Then
' This handles the "(" character using Shift + 9
btnLeftBracket.PerformClick() ' Triggers the left parenthesis button click
ElseIf e.KeyCode = Keys.D0 AndAlso e.Shift Then
' This handles the ")" character using Shift + 0
btnRightBracket.PerformClick() ' Triggers the right parenthesis button click
' Check for the percent sign using its ASCII code (37)
ElseIf e.KeyCode = Keys.D5 AndAlso e.Shift Then
btnModules.PerformClick() ' Triggers the percent button click
ElseIf e.KeyCode = Keys.D8 AndAlso e.Shift Then
' This handles the "*" character using Shift + 9
btnMultiplication.PerformClick()
ElseIf e.KeyCode = Keys.D0 Then
' This handles the "0" character
btnInput0.PerformClick()
ElseIf e.KeyCode = Keys.D1 Then
' This handles the "1" character
btnInput1.PerformClick()
ElseIf e.KeyCode = Keys.D2 Then
' This handles the "2" character
btnInput2.PerformClick()
ElseIf e.KeyCode = Keys.D3 Then
' This handles the "3" character
btnInput3.PerformClick()
ElseIf e.KeyCode = Keys.D4 Then
' This handles the "4" character
btnInput4.PerformClick()
ElseIf e.KeyCode = Keys.D5 Then
' This handles the "5" character
btnInput5.PerformClick()
ElseIf e.KeyCode = Keys.D6 Then
' This handles the "6" character
btnInput6.PerformClick()
ElseIf e.KeyCode = Keys.D7 Then
' This handles the "7" character
btnInput7.PerformClick()
ElseIf e.KeyCode = Keys.D8 Then
' This handles the "8" character
btnInput8.PerformClick()
ElseIf e.KeyCode = Keys.D9 Then
' This handles the "9" character
btnInput9.PerformClick()

End If
End Sub

Private Sub AnswerHistoryToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles AnswerHistoryToolStripMenuItem.Click
'Code for extend form
Me.Height = 411
Me.Width = 587
txtAnswer.Width = 334
End Sub

Private Sub btnClearAnswerHistory_Click(sender As Object, e As EventArgs) Handles btnClearAnswerHistory.Click
lstAnswer.Nodes.Clear()
End Sub
End Class
4 changes: 2 additions & 2 deletions scientific calc/bin/Debug/Scientific Calculator.application
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<framework targetVersion="4.5.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="Scientific Calculator.exe.manifest" size="5148">
<dependentAssembly dependencyType="install" codebase="Scientific Calculator.exe.manifest" size="5149">
<assemblyIdentity name="Scientific Calculator.exe" version="1.0.0.1" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>hSwIsIqBpat72BVResX5MCZ9Awv+gb1p3nzb2SCIABw=</dsig:DigestValue>
<dsig:DigestValue>cTSDXlXHfXs6dj9iRacMCnyEdcc6i0jQ/F8J0VXbJLM=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/bin/Debug/Scientific Calculator.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions scientific calc/bin/Debug/Scientific Calculator.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="98304">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="102400">
<assemblyIdentity name="Scientific Calculator" version="1.0.5.2" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>JA8kebm8KdUmLLoyELSasqDKKbMFu9iwXPZ8wM9xH+s=</dsig:DigestValue>
<dsig:DigestValue>B03Ci/n/l4xWYC2ywkZajCCVpk8X4JVoAnIoCXzC+ZM=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/bin/Debug/Scientific Calculator.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>FKf6PcG6aGKML5mUN522umEbV2Qz2hsAE3bLSZdQ4rY=</dsig:DigestValue>
<dsig:DigestValue>ZXsu5TXvGZvsGmYknMuF6nipdvYw2dzfp3V/BYO4Ous=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/bin/Release/Scientific Calculator.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="95232">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="98816">
<assemblyIdentity name="Scientific Calculator" version="1.0.5.2" language="neutral" processorArchitecture="amd64" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>XRSU0C2kqnR7b7Rm0CQy17CzKpStDqTWCIGDSBz5t1Y=</dsig:DigestValue>
<dsig:DigestValue>WNciDSW0N7IM6oVeathdhtiDII9CQNW7T+SJo/Q3flw=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/bin/Release/Scientific Calculator.pdb
Binary file not shown.
Binary file not shown.
4 changes: 2 additions & 2 deletions scientific calc/obj/Debug/Scientific Calculator.application
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
<framework targetVersion="4.5.2" profile="Full" supportedRuntime="4.0.30319" />
</compatibleFrameworks>
<dependency>
<dependentAssembly dependencyType="install" codebase="Scientific Calculator.exe.manifest" size="5148">
<dependentAssembly dependencyType="install" codebase="Scientific Calculator.exe.manifest" size="5149">
<assemblyIdentity name="Scientific Calculator.exe" version="1.0.0.1" publicKeyToken="0000000000000000" language="neutral" processorArchitecture="msil" type="win32" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>hSwIsIqBpat72BVResX5MCZ9Awv+gb1p3nzb2SCIABw=</dsig:DigestValue>
<dsig:DigestValue>cTSDXlXHfXs6dj9iRacMCnyEdcc6i0jQ/F8J0VXbJLM=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/obj/Debug/Scientific Calculator.exe
Binary file not shown.
4 changes: 2 additions & 2 deletions scientific calc/obj/Debug/Scientific Calculator.exe.manifest
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="98304">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="102400">
<assemblyIdentity name="Scientific Calculator" version="1.0.5.2" language="neutral" processorArchitecture="msil" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>JA8kebm8KdUmLLoyELSasqDKKbMFu9iwXPZ8wM9xH+s=</dsig:DigestValue>
<dsig:DigestValue>B03Ci/n/l4xWYC2ywkZajCCVpk8X4JVoAnIoCXzC+ZM=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/obj/Debug/Scientific Calculator.pdb
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>FKf6PcG6aGKML5mUN522umEbV2Qz2hsAE3bLSZdQ4rY=</dsig:DigestValue>
<dsig:DigestValue>ZXsu5TXvGZvsGmYknMuF6nipdvYw2dzfp3V/BYO4Ous=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/obj/Release/Scientific Calculator.exe
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@
</dependentAssembly>
</dependency>
<dependency>
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="95232">
<dependentAssembly dependencyType="install" allowDelayedBinding="true" codebase="Scientific Calculator.exe" size="98816">
<assemblyIdentity name="Scientific Calculator" version="1.0.5.2" language="neutral" processorArchitecture="amd64" />
<hash>
<dsig:Transforms>
<dsig:Transform Algorithm="urn:schemas-microsoft-com:HashTransforms.Identity" />
</dsig:Transforms>
<dsig:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha256" />
<dsig:DigestValue>XRSU0C2kqnR7b7Rm0CQy17CzKpStDqTWCIGDSBz5t1Y=</dsig:DigestValue>
<dsig:DigestValue>WNciDSW0N7IM6oVeathdhtiDII9CQNW7T+SJo/Q3flw=</dsig:DigestValue>
</hash>
</dependentAssembly>
</dependency>
Expand Down
Binary file modified scientific calc/obj/Release/Scientific Calculator.pdb
Binary file not shown.
Binary file not shown.

0 comments on commit 6c8eeb6

Please sign in to comment.