calculator standart

21
Calculator_V2.00. Visual Studio Languages forums , .NET Framework forums > Visual Basic General discussion 1 Sign in to vote Hi ALL, This lot is my latest version. Built with the Express "Orcas" Edition,( which you can install alongside Visual Studio or another Express Edition ) from here. >>>> http://msdn.microsoft.com/vstudio/express/future/ default.aspx or here>> http://msdn.microsoft.com/vstudio/express/future/downloads/ default.aspx

Upload: alberthutagalung

Post on 26-Sep-2015

260 views

Category:

Documents


0 download

TRANSCRIPT

Calculator_V2.00. Visual Studio Languages forums ,.NET Framework forums > Visual Basic General discussion

1

Sign in to vote Hi ALL,This lot is my latest version.Built with the Express "Orcas" Edition,( which you can install alongside Visual Studio or another Express Edition ) from here. >>>>http://msdn.microsoft.com/vstudio/express/future/default.aspxor here>>http://msdn.microsoft.com/vstudio/express/future/downloads/default.aspxLeft-click on the filename Calculator_V2.zipwhen you download the project from here. >>>>http://efuncenter.5squid.com/Calculator_V2/I have now added the .exe file to the download area.Left-click on Calculator_V2.exe to Run or SAVE the file.Still not as many buttons. checkboxes and radiobuttons as the Windows version in scientific mode.It uses; 1 Checkbox 40 Buttons !! 1 Textbox 3 RadioButtons on 1 Panel 2LabelsI have kept it as simple as possible for beginners to follow.See a picture of the layout of it here. >>>>http://s13.photobucket.com/albums/a272/u-might-want-this/?action=view&current=Calculator_Pic.jpgI will try to put the project as a ZIP file on the internet for download, in case anyone is interested?Version_1.00 is in this thread.>>http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1418930&SiteID=1Regards,S_DS_________________________________________________Public Class Form1'Variable to hold the sum.Dim sum As Double = 0'String to hold the operand.Dim operand As String = ""'Holds value1 for use later'when "=" button is clicked.Dim value1 As Double = 0'Holds value2 for use later'when "=" buttonis clicked.Dim value2 As Double = 0'To indicate whether "Checkbox1" as "Inverse"'is ticked or not.Dim isTicked As Boolean = False'Variable to hold the "MEMORY" value.Dim memory As Double'ConversionFactor used for trigonometry functions'set to the default value for DEGREES.Dim conversionFactor As Double = 180 / Math.PI'The swap variable is used by'one of the calculator functions.Dim swap As DoublePrivate Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load'Set the default mode to DEGREES.RadioButton1.Checked = TrueMe.Text = "Calculator_V2.00"End SubPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ClickTextBox1.Text += "1"End SubPrivate Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.ClickTextBox1.Text += "2"End SubPrivate Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.ClickTextBox1.Text += "3"End SubPrivate Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.ClickTextBox1.Text += "4"End SubPrivate Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.ClickTextBox1.Text += "5"End SubPrivate Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.ClickTextBox1.Text += "6"End SubPrivate Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.ClickTextBox1.Text += "7"End SubPrivate Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.ClickTextBox1.Text += "8"End SubPrivate Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.ClickTextBox1.Text += "9"End Sub'This button has the zero on it.Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.ClickTextBox1.Text += "0"End Sub'This button has the decimal point dot on it.Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.ClickDim dot As Boolean = FalseIf TextBox1.Text.IndexOf(".") >= 0 Then dot = TrueIf dot = False Then TextBox1.Text += "."End Sub'This button has "=" on it.Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Clickvalue2 = Val(TextBox1.Text)Select Case operandCase Is = "+"TextBox1.Text = (value1 + value2).ToStringCase Is = "-"TextBox1.Text = (value1 - value2).ToStringCase Is = "X"TextBox1.Text = (value1 * value2).ToStringCase Is = "/"If value2 0 ThenTextBox1.Text = (value1 / value2).ToStringEnd IfCase Is = "\"If value2 0 ThenTextBox1.Text = (CInt(value1) \ CInt(value2)).ToStringEnd IfCase Is = "SIN"If CheckBox1.Checked = False ThenTextBox1.Text = Math.Sin(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Asin(value1) * conversionFactorEnd IfCase Is = "COS"If CheckBox1.Checked = False ThenTextBox1.Text = Math.Cos(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Acos(value1) * conversionFactorEnd IfCase Is = "TAN"If CheckBox1.Checked = False ThenTextBox1.Text = Math.Tan(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Atan(value1) * conversionFactorEnd IfEnd SelectEnd Sub'This button has "+" on it.Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Clickoperand = "+"If checkInput() = True Then value1 = CDbl(TextBox1.Text)TextBox1.Clear()End Sub'This button has "-" on it.Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Clickoperand = "-"If checkInput() = True Then value1 = CDbl(TextBox1.Text)TextBox1.Clear()End Sub'This button has "X" on it.Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Clickoperand = "X"If checkInput() = True Then value1 = CDbl(TextBox1.Text)TextBox1.Clear()End Sub'This button has "/" on it.Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Clickoperand = "/"If checkInput() = True Then value1 = CDbl(TextBox1.Text)TextBox1.Clear()End Sub'This button has "C" on it.Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.ClickTextBox1.Clear()sum = 0End Sub'This button has "CE" on it for CLEAR ENTRY.Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.ClickTextBox1.Clear()End Sub'This button has "\" on it for integer division.Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button19.Clickoperand = "\"If checkInput() = True Then value1 = CDbl(TextBox1.Text)TextBox1.Clear()End Sub'This button has "SIN" on it.Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseoperand = "SIN"value1 = CDbl(TextBox1.Text)If CheckBox1.Checked = False ThenTextBox1.Text = Math.Sin(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Asin(value1) * conversionFactorEnd IfEnd IfEnd Sub'This button has "COS" on it.Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button21.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseoperand = "COS"value1 = CDbl(TextBox1.Text)If CheckBox1.Checked = False ThenTextBox1.Text = Math.Cos(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Acos(value1) * conversionFactorEnd IfEnd IfEnd Sub'This button has "TAN" on it.Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button22.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseoperand = "TAN"value1 = CDbl(TextBox1.Text)If CheckBox1.Checked = False ThenTextBox1.Text = Math.Tan(value1 / conversionFactor)ElseCheckBox1.Checked = FalseTextBox1.Text = Math.Atan(value1) * conversionFactorEnd IfEnd IfEnd Sub'This button has "Pi" on it.Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button23.ClickTextBox1.Text = Math.PI.ToStringEnd Sub'This button has "Clr All" on it to CLEAR ALL current working values.Private Sub Button24_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button24.Clickvalue1 = 0value2 = 0memory = 0TextBox1.Clear()Label1.Text = NothingCheckBox1.Checked = FalseEnd SubPrivate Function checkInput() As BooleanIf IsNumeric(TextBox1.Text) = True And TextBox1.Text "" And TextBox1.Text Nothing ThenReturn TrueElseReturn FalseEnd IfEnd Function'This button has "MS" on it for "MEMORY STORE".Private Sub Button25_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button25.ClickIf checkInput() = True Then memory = CDbl(TextBox1.Text)If memory 0 ThenLabel1.Text = "M"ElseLabel1.Text = NothingEnd IfEnd Sub'This button has "MC" on it for "MEMORY CANCEL"Private Sub Button26_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button26.Clickmemory = 0Label1.Text = NothingEnd Sub'This button has "M+" on it for "MEMORY PLUS"'Adds the value in the textbox to the memory value.Private Sub Button27_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button27.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElsememory += CDbl(TextBox1.Text)If memory 0 Then Label1.Text = "M"End IfEnd Sub'This button has "M-" on it for "MEMORY MINUS"'Subtracts the value in the textbox from the memory value.Private Sub Button28_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button28.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElsememory -= CDbl(TextBox1.Text)If memory 0 Then Label1.Text = "M"End IfEnd Sub'This button has "MX" on it for "MEMORY TIMES"'Multiplies the textbox value with the'value in memory, putting the result in the memory.Private Sub Button29_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button29.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElsememory *= CDbl(TextBox1.Text)If memory 0 Then Label1.Text = "M"End IfEnd Sub'This button has "M/" on it.'Attempts to divide the memory value by the value'by the value in the textbox, putting the result in the memory.Private Sub Button30_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button30.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElseIf checkInput() = True And Val(TextBox1.Text) 0 Then memory /= CDbl(TextBox1.Text)If memory 0 Then Label1.Text = "M"End IfEnd Sub'This button has "M\" on it.'Attempts to do INTEGER division the memory value'by the value in the textbox, putting the result in the memory.Private Sub Button31_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button31.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElseIf checkInput() = True And Val(TextBox1.Text) 0 Then memory = CInt(memory) \ CInt(TextBox1.Text)If memory 0 Then Label1.Text = "M"End IfEnd Sub'This button has "MR" on it for "MEMORY RECALL"Private Sub Button32_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button32.ClickIf memory 0 ThenLabel1.Text = "M"TextBox1.Text = CStr(memory)ElseLabel1.Text = NothingEnd IfEnd Sub'This button has "Sqrt" on it to calculate the square root.Private Sub Button33_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button33.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElseIf checkInput() = True Then TextBox1.Text = Math.Sqrt(CDbl(TextBox1.Text))End IfEnd Sub'This button has "+ / -" on it to change the sign of the number.Private Sub Button34_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button34.ClickIf String.IsNullOrEmpty(TextBox1.Text) ThenExit SubElseIf checkInput() = True Then TextBox1.Text = ((CDbl(TextBox1.Text)) * -1).ToStringEnd IfEnd Sub'This button has "LOG10" on it to return the'LOG of a number to base 10.Private Sub Button35_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button35.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseoperand = "LOG10"value1 = CDbl(TextBox1.Text)TextBox1.Text = Math.Log10(value1)End IfEnd Sub'This button has "LOG e" on it to return the'LOG of a number to base little "e"'which is approx 2.7182818284590452353602874713527.Private Sub Button36_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button36.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseoperand = "LOG"value1 = CDbl(TextBox1.Text)TextBox1.Text = Math.Log(value1)End IfEnd Sub'This button has "X M" on it.'This exchanges the memory value with the display value,'basically swaps them.Private Sub Button37_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button37.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElsevalue1 = CDbl(TextBox1.Text)If memory Nothing Thenswap = memoryTextBox1.Text = swapmemory = value1End IfEnd IfEnd Sub'Swaps the two working values around'so that instead of doing say 10 / 5'click on button "X Y" to do 5 / 10Private Sub Button38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button38.Clickswap = value1value1 = CDbl(TextBox1.Text)value2 = swapTextBox1.Text = CStr(value2)End Sub'This button has "1/X" on it.'It divides 1 by the display value.Private Sub Button39_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button39.ClickIf String.IsNullOrEmpty(TextBox1.Text) = True ThenExit SubElseIf CDbl(TextBox1.Text) 0 Then TextBox1.Text = (1 / CDbl(TextBox1.Text)).ToStringEnd IfEnd Sub'Set the conversionFactor to work in DEGREES.Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChangedconversionFactor = 180 / Math.PIEnd Sub'Set the conversionFactor to work in RADIANS.Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChangedconversionFactor = 1End Sub'Set the conversionFactor to work in GRADIANS.Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChangedconversionFactor = 200 / Math.PIEnd Sub'My "Modest" 'About' meesage.Private Sub Button40_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button40.ClickMessageBox.Show("Calculator_V2.00 by S_DS ," & vbNewLine & " I extended the code on 26th June,2007.", "About Calculator_V2.00")End SubEnd Class