0% found this document useful (0 votes)
68 views6 pages

Codes

This document contains the code for a basic calculator application. It defines variables to store operands and operators, includes event handler subroutines for each button click to perform the appropriate calculation or display operation, and uses a select case structure to evaluate the operator and perform the calculation when the equal button is clicked.

Uploaded by

ryle34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views6 pages

Codes

This document contains the code for a basic calculator application. It defines variables to store operands and operators, includes event handler subroutines for each button click to perform the appropriate calculation or display operation, and uses a select case structure to evaluate the operator and perform the calculation when the equal button is clicked.

Uploaded by

ryle34
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Public Class Form1

Dim operand1 As Double


Dim operand2 As Double
Dim [operator] As String
Dim MemorySave

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


btnZero.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub
Private Sub btnOne_Click(sender As System.Object, e As System.EventArgs) Handles
btnOne.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub
Private Sub btnTwo_Click(sender As System.Object, e As System.EventArgs) Handles
btnTwo.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnThree.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnFour.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnFive.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnSix.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnSeven.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnEight.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnNine.Click
If txtDisplay.Text = "0" Then
txtDisplay.Text = sender.text
Else
txtDisplay.Text = txtDisplay.Text + sender.TEXT
End If
End Sub

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


btnAC.Click
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
txtDisplay.Text = Val(0)

End Sub

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


Button1.Click
txtDisplay.Text = Val(0)
End Sub
Private Sub btnBackspace_Click(sender As System.Object, e As System.EventArgs)
Handles btnBackspace.Click
If txtDisplay.Text < " " Then
txtDisplay.Text = Mid(txtDisplay.Text, 1, Len(txtDisplay.Text) - 1 + 1)
Else
txtDisplay.Text = Mid(txtDisplay.Text, 1, Len(txtDisplay.Text) - 1)
End If
If txtDisplay.Text = "" Then
txtDisplay.Text = Val(0)
End If

End Sub

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


Button3.Click
MemorySave = Val(txtDisplay.Text)

End Sub

Private Sub btnMemoryRecall_Click(sender As System.Object, e As System.EventArgs)


Handles btnMemoryRecall.Click
txtDisplay.Text = MemorySave
End Sub

Private Sub btnMemoryPlus_Click(sender As System.Object, e As System.EventArgs)


Handles btnMemoryPlus.Click
txtDisplay.Text = Val(txtDisplay.Text) + MemorySave
End Sub

Private Sub btnMemoryMinus_Click(sender As System.Object, e As System.EventArgs)


Handles btnMemoryMinus.Click
txtDisplay.Text = Val(txtDisplay.Text) - MemorySave
End Sub

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


btnSign.Click
txtDisplay.Text = -Val(txtDisplay.Text)
End Sub

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


btnPeriod.Click
If InStr(txtDisplay.Text, ".") Then
Exit Sub
Else
txtDisplay.Text = txtDisplay.Text & "."
End If
End Sub

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


btnMultiply.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "*"
End Sub

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


btnEqual.Click
operand2 = Val(txtDisplay.Text)
Dim RESULT

Select Case [operator]

Case "*"
RESULT = operand1 * operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""

Case "/"
RESULT = operand1 / operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""

Case "+"
RESULT = operand1 + operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
Case "-"
RESULT = operand1 - operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
Case "^"
RESULT = operand1 ^ operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
Case "\"
RESULT = operand1 \ operand2
txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
Case "mod"

RESULT = operand1 Mod operand2


txtDisplay.Text = RESULT.ToString
operand1 = Val(0)
operand2 = Val(0)
[operator] = ""
End Select
End Sub

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


btnPlus.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Clear()
[operator] = "+"
End Sub

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


btnDIVIDe.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "/"
End Sub

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


btnEXPonent.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "^"
End Sub

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


btnIntDiv.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "\"
End Sub

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


btnModulo.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "mod"
End Sub

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


btnMinus.Click
operand1 = Val(txtDisplay.Text)
txtDisplay.Text = Val(0)
[operator] = "-"
End Sub

Private Sub btnReciprocal_Click(sender As System.Object, e As System.EventArgs)


Handles btnReciprocal.Click
txtDisplay.Text = 1 / Val(txtDisplay.Text)
End Sub

Private Sub Button38_Click(sender As Object, e As EventArgs) Handles Button38.Click

End Sub
Private Sub CmdSin_Click()

End Sub
Private Sub Button35_Click(sender As Object, e As EventArgs) Handles Button35.Click

End Sub

Private Sub Button36_Click(sender As Object, e As EventArgs) Handles Button36.Click


Dim x As Integer
Dim root As Integer
root = x
root = root ^ (1 / 2)
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load


txtDisplay.Text = "0"
End Sub
End Class

You might also like