Thursday, December 15, 2011

Very Simple Calculator

1. Design the User Interface below.



2. Enter the code as follows:


Public Class frmSimpleCalculator

Private Sub btnCompute_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompute.Click

Dim First As Double
Dim Second As Double

First = txtFirstNumber.Text
Second = txtSecondNumber.Text

If rdoAddition.Checked = True Then
lbl3.Text = First + Second
End If

If rdoSubtraction.Checked = True Then
lbl3.Text = First - Second
End If

If rdoMutiplication.Checked = True Then
lbl3.Text = First * Second
End If

If rdoDivision.Checked = True Then
lbl3.Text = First / Second
End If

If rdoIntegerDivision.Checked = True Then
lbl3.Text = First \ Second
End If

If rdoModulus.Checked = True Then
lbl3.Text = First Mod Second
End If

If rdoExponentiation.Checked = True Then
lbl3.Text = First ^ Second
End If

If Double.TryParse(txtFirstNumber.Text, First) = True And Double.TryParse(txtSecondNumber.Text, Second) = True Then

First = txtFirstNumber.Text
Second = txtSecondNumber.Text

If rdoAddition.Checked = True Then
txtResult.Text = First + Second
End If

If rdoSubtraction.Checked = True Then
txtResult.Text = First - Second
End If

If rdoMutiplication.Checked = True Then
txtResult.Text = First * Second
End If

If rdoDivision.Checked = True Then
txtResult.Text = First / Second
End If

If rdoIntegerDivision.Checked = True Then
txtResult.Text = First \ Second
End If

If rdoModulus.Checked = True Then

txtResult.Text = First Mod Second
End If

If rdoExponentiation.Checked = True Then
txtResult.Text = First ^ Second
End If

Else : MsgBox("Enter a number!", MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Warning")
End If
End Sub

Private Sub btnExit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnExit.Click
End
End Sub

End Class

No comments:

Post a Comment