Вы находитесь на странице: 1из 19

Calculator_V2.00.

Visual Studio Languages forums


,
.NET Framework forums
>
Visual Basic

General discussion

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

Left-click on the filename Calculator_V2.zip when 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;

o 1 Checkbox
o 40 Buttons !!
o 1 Textbox
o 3 RadioButtons on
o 1 Panel
o 2 Labels

I 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.jpg

I 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=1

Regards,

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 Double
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
'Set the default mode to DEGREES.
RadioButton1.Checked = True
Me.Text = "Calculator_V2.00"
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
TextBox1.Text += "1"
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
TextBox1.Text += "2"
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button3.Click
TextBox1.Text += "3"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button4.Click
TextBox1.Text += "4"
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button5.Click
TextBox1.Text += "5"
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button6.Click
TextBox1.Text += "6"
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button7.Click
TextBox1.Text += "7"
End Sub
Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button8.Click
TextBox1.Text += "8"
End Sub
Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button9.Click
TextBox1.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.Click
TextBox1.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.Click
Dim dot As Boolean = False
If TextBox1.Text.IndexOf(".") >= 0 Then dot = True
If 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.Click
value2 = Val(TextBox1.Text)
Select Case operand
Case Is = "+"
TextBox1.Text = (value1 + value2).ToString
Case Is = "-"
TextBox1.Text = (value1 - value2).ToString
Case Is = "X"
TextBox1.Text = (value1 * value2).ToString
Case Is = "/"
If value2 <> 0 Then
TextBox1.Text = (value1 / value2).ToString
End If
Case Is = "\"
If value2 <> 0 Then
TextBox1.Text = (CInt(value1) \ CInt(value2)).ToString
End If
Case Is = "SIN"

If CheckBox1.Checked = False Then


TextBox1.Text = Math.Sin(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Asin(value1) * conversionFactor
End If
Case Is = "COS"
If CheckBox1.Checked = False Then
TextBox1.Text = Math.Cos(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Acos(value1) * conversionFactor
End If
Case Is = "TAN"
If CheckBox1.Checked = False Then
TextBox1.Text = Math.Tan(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Atan(value1) * conversionFactor
End If
End Select
End Sub
'This button has "+" on it.
Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button13.Click
operand = "+"

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.Click
operand = "-"
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.Click
operand = "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.Click
operand = "/"
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.Click
TextBox1.Clear()

sum = 0
End 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.Click
TextBox1.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.Click
operand = "\"
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.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
operand = "SIN"
value1 = CDbl(TextBox1.Text)
If CheckBox1.Checked = False Then
TextBox1.Text = Math.Sin(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Asin(value1) * conversionFactor

End If
End If
End Sub
'This button has "COS" on it.
Private Sub Button21_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button21.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
operand = "COS"
value1 = CDbl(TextBox1.Text)
If CheckBox1.Checked = False Then
TextBox1.Text = Math.Cos(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Acos(value1) * conversionFactor
End If
End If
End Sub
'This button has "TAN" on it.
Private Sub Button22_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button22.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
operand = "TAN"
value1 = CDbl(TextBox1.Text)

If CheckBox1.Checked = False Then


TextBox1.Text = Math.Tan(value1 / conversionFactor)
Else
CheckBox1.Checked = False
TextBox1.Text = Math.Atan(value1) * conversionFactor
End If
End If
End Sub
'This button has "Pi" on it.
Private Sub Button23_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button23.Click
TextBox1.Text = Math.PI.ToString
End 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.Click
value1 = 0
value2 = 0
memory = 0
TextBox1.Clear()
Label1.Text = Nothing
CheckBox1.Checked = False
End Sub
Private Function checkInput() As Boolean
If IsNumeric(TextBox1.Text) = True And TextBox1.Text <> "" And TextBox1.Text <> Nothing Then
Return True
Else

Return False
End If
End 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.Click
If checkInput() = True Then memory = CDbl(TextBox1.Text)
If memory <> 0 Then
Label1.Text = "M"
Else
Label1.Text = Nothing
End If
End 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.Click
memory = 0
Label1.Text = Nothing
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
memory += CDbl(TextBox1.Text)

If memory <> 0 Then Label1.Text = "M"


End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
memory -= CDbl(TextBox1.Text)
If memory <> 0 Then Label1.Text = "M"
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
memory *= CDbl(TextBox1.Text)
If memory <> 0 Then Label1.Text = "M"
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
If checkInput() = True And Val(TextBox1.Text) <> 0 Then memory /= CDbl(TextBox1.Text)
If memory <> 0 Then Label1.Text = "M"
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
If checkInput() = True And Val(TextBox1.Text) <> 0 Then memory = CInt(memory) \ CInt(TextBox1.Text)
If memory <> 0 Then Label1.Text = "M"
End If
End 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.Click
If memory <> 0 Then

Label1.Text = "M"
TextBox1.Text = CStr(memory)
Else
Label1.Text = Nothing
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
If checkInput() = True Then TextBox1.Text = Math.Sqrt(CDbl(TextBox1.Text))
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) Then
Exit Sub
Else
If checkInput() = True Then TextBox1.Text = ((CDbl(TextBox1.Text)) * -1).ToString
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
operand = "LOG10"
value1 = CDbl(TextBox1.Text)
TextBox1.Text = Math.Log10(value1)
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
operand = "LOG"
value1 = CDbl(TextBox1.Text)
TextBox1.Text = Math.Log(value1)
End If
End 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.Click
If String.IsNullOrEmpty(TextBox1.Text) = True Then
Exit Sub
Else
value1 = CDbl(TextBox1.Text)
If memory <> Nothing Then
swap = memory
TextBox1.Text = swap
memory = value1
End If
End If
End Sub
'Swaps the two working values around
'so that instead of doing say 10 / 5
'click on button "X <--> Y" to do 5 / 10
Private Sub Button38_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button38.Click
swap = value1
value1 = CDbl(TextBox1.Text)
value2 = swap
TextBox1.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.Click

If String.IsNullOrEmpty(TextBox1.Text) = True Then


Exit Sub
Else
If CDbl(TextBox1.Text) <> 0 Then TextBox1.Text = (1 / CDbl(TextBox1.Text)).ToString
End If
End Sub
'Set the conversionFactor to work in DEGREES.
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton1.CheckedChanged
conversionFactor = 180 / Math.PI
End Sub
'Set the conversionFactor to work in RADIANS.
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton2.CheckedChanged
conversionFactor = 1
End Sub
'Set the conversionFactor to work in GRADIANS.
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles RadioButton3.CheckedChanged
conversionFactor = 200 / Math.PI
End Sub
'My "Modest" 'About' meesage.
Private Sub Button40_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button40.Click
MessageBox.Show("Calculator_V2.00 by S_DS ," & vbNewLine & " I extended the code on 26th
June,2007.", "About Calculator_V2.00")
End Sub
End Class

Вам также может понравиться