0% found this document useful (0 votes)
89 views2 pages

' Lbldisplay - Text ""

This document contains code for a basic calculator application. It defines variables to store the display value, operands, and operator for calculations. Methods are included to handle button clicks for numbers, operators, clear, and equals. When a number button is clicked, the display is updated. Operator buttons set the operand and operator variables. The equals button performs the calculation and displays the result.

Uploaded by

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

' Lbldisplay - Text ""

This document contains code for a basic calculator application. It defines variables to store the display value, operands, and operator for calculations. Methods are included to handle button clicks for numbers, operators, clear, and equals. When a number button is clicked, the display is updated. Operator buttons set the operand and operator variables. The equals button performs the calculation and displays the result.

Uploaded by

sathisha123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

Dim clearDisplay As Boolean

Dim Operand1 As Double, Operand2 As Double


Dim [Operator] As String

Private Sub bttn1_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link], [Link], [Link], _
[Link], [Link],
[Link], [Link], [Link], [Link], [Link]
If clearDisplay Then
[Link] = ""
clearDisplay = False
End If
[Link] = Val([Link] + [Link])
End Sub

Private Sub bttnPeriod_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
If [Link](".") > 0 Then
Exit Sub
Else
[Link] = [Link] & "."
End If
End Sub

Private Sub bttnPlus_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Operand1 = Val([Link])
[Operator] = "+"
clearDisplay = True
End Sub

Private Sub bttnEquals_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Dim result As Double
Operand2 = Val([Link])
Try
Select Case [Operator]
Case "+"
result = Operand1 + Operand2
Case "-"
result = Operand1 - Operand2
Case "*"
result = Operand1 * Operand2
Case "/"
If Operand2 <> "0" Then [Link] = result
End Select
Catch exc As Exception
MsgBox([Link])
result = "ERROR"
Finally
[Link] = result
clearDisplay = True
End Try
End Sub

Private Sub bttnMinus_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Operand1 = Val([Link])
[Operator] = "-"
clearDisplay = True ' [Link] = ""
End Sub
Private Sub bttnMultiply_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
Operand1 = Val([Link])
[Operator] = "*"
clearDisplay = True
End Sub

Private Sub bttnDivide_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
Operand1 = Val([Link])
[Operator] = "/"
clearDisplay = True
End Sub

Private Sub CalculatorForm_KeyPress(ByVal sender As Object, ByVal e As


[Link]) Handles [Link]
If [Link]([Link]) Or [Link] = "." Then
If clearDisplay Then
[Link] = ""
clearDisplay = False
End If
[Link] = [Link] + [Link]
End If
End Sub

Private Sub bttnClear_Click(ByVal sender As [Link], ByVal e As


[Link]) Handles [Link]
[Link] = ""
End Sub

You might also like