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

Practical No : 3

Aim: Create a calculator that can be used for adding, subtracting, multiplication and division. Source code:
Public Class Form1 Dim operand1 As Double Dim operand2 As Double Dim [operator] As String Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button0.Click If (TextBox1.Text.Length <= 1) Then TextBox1.Text = Button0.Text Else TextBox1.Text += Button0.Text End If End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click TextBox1.Text += Button1.Text End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text += Button2.Text End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click TextBox1.Text += Button3.Text End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click TextBox1.Text += Button4.Text End Sub Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click TextBox1.Text += Button5.Text End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click TextBox1.Text += Button6.Text End Sub Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click TextBox1.Text += Button7.Text End Sub Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click TextBox1.Text += Button8.Text End Sub Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click TextBox1.Text += Button9.Text End Sub Private Sub Buttonclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonclear.Click TextBox1.Text = "" End Sub Private Sub Buttonplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonplus.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "+" End Sub Private Sub Buttonequal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonequal.Click Dim result As Double operand2 = TextBox1.Text If [operator] = "+" Then result = operand1 + operand2 ElseIf [operator] = "-" Then result = operand1 - operand2 ElseIf [operator] = "*" Then result = operand1 * operand2 ElseIf [operator] = "/" Then result = operand1 / operand2 End If TextBox1.Text = result.ToString() End Sub Private Sub Buttonminus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonminus.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "-" End Sub

Private Sub Buttonmulti_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonmulti.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "*" End Sub Private Sub Buttondivide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttondivide.Click operand1 = Val(TextBox1.Text) TextBox1.Text = "" TextBox1.Focus() [operator] = "/" End Sub Private Sub Buttonpoint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Buttonpoint.Click If InStr(TextBox1.Text, ".") > 0 Then Exit Sub Else TextBox1.Text = TextBox1.Text & "." End If End Sub End Class

Output : 3

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