Public Class frmCalculator
Private Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
'Retrieve
two numbers from textboxes and add them together
'then
display operator and result
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim dblTotal As Double
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
dblTotal = dblNum1 + dblNum2
lblMath.Text = "(+) Plus"
lblEquals.Text = "= " &
dblTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnSubtract_Click(sender As Object, e As EventArgs) Handles btnSubtract.Click
'Retrieve
two numbers from textboxes and subtract second number from first number
'then
display operator and result
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim dblTotal As Double
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
dblTotal = dblNum1 - dblNum2
lblMath.Text = "(-) Minus"
lblEquals.Text = "= " &
dblTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnMultiply_Click(sender As Object, e As EventArgs) Handles btnMultiply.Click
'Retrieve
two numbers from textboxes and multiply them together
'then
display operator and result
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim dblTotal As Double
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
dblTotal = dblNum1 * dblNum2
lblMath.Text = "(*) Times"
lblEquals.Text = "= " &
dblTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnExponent_Click(sender As Object, e As EventArgs) Handles btnExponent.Click
'Retrieve
two numbers from textboxes and use the order of the first number to the power
of the second number
'then
display operator and result
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim dblTotal As Double
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
dblTotal = dblNum1 ^ dblNum2
lblMath.Text = "(^) To The Power Of"
lblEquals.Text = "= " &
dblTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnDivide_Click(sender As Object, e As EventArgs) Handles btnDivide.Click
'Retrieve
two numbers from textboxes and divide the first number by the second number
'then
display operator and result
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim dblTotal As Double
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
dblTotal = dblNum1 / dblNum2
lblMath.Text = "(/) Divided By"
lblEquals.Text = "= " &
dblTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnIntDivide_Click(sender As Object, e As EventArgs) Handles btnIntDivide.Click
'Retrieve
two numbers from textboxes and divide the first number by the second number
'then
display operator and result as a whole number
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim intTotal As Integer
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
intTotal = dblNum1 \ dblNum2
lblMath.Text = "(\) Interger Divided By"
lblEquals.Text = "= " &
intTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnModulus_Click(sender As Object, e As EventArgs) Handles btnModulus.Click
'Retrieve
two numbers from textboxes and divide the first number by the second number
'then
display operator and result as only the remainer from dividing
Dim strNumber As String
Dim dblNum1 As Double
Dim dblNum2 As Double
Dim intTotal As Integer
'if
both are numeric complete the operation and display total
If IsNumeric(tbNumTwo.Text) And IsNumeric(tbNumOne.Text) Then
dblNum1 = Convert.ToDouble(tbNumOne.Text)
dblNum2 = Convert.ToDouble(tbNumTwo.Text)
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
intTotal = dblNum1 Mod dblNum2
lblMath.Text = "MOD"
lblEquals.Text = "= " &
intTotal.ToString("G")
'if
only first textbox has a numeric value
'store
it in a string variable and request entry for second textbox
ElseIf IsNumeric(tbNumOne.Text) Then
strNumber = tbNumOne.Text
dblNum1 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = False
lblRequestTwo.Visible = True
tbNumTwo.Focus()
lblEquals.Text = "?"
'if
only second textbox has a numeric value
'store
it in a string variable and request entry for first textbox
ElseIf IsNumeric(tbNumTwo.Text) Then
strNumber = tbNumTwo.Text
dblNum2 = Convert.ToDouble(strNumber)
lblRequestOne.Visible = True
lblRequestTwo.Visible = False
tbNumOne.Focus()
lblEquals.Text = "?"
'else
request a number for both
Else
lblRequestOne.Visible = True
lblRequestTwo.Visible = True
tbNumOne.Focus()
lblEquals.Text = "?"
End If
End Sub
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clear
will empty the textboxes and operator label
'then
place the focus on the first text boxes
tbNumOne.Text = ""
tbNumTwo.Text = ""
lblMath.Text = ""
lblEquals.Text = ""
lblRequestOne.Visible = False
lblRequestTwo.Visible = False
tbNumOne.Focus()
End Sub
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
'Exit
will call the close function
Close()
End Sub
End Class
No comments:
Post a Comment
Thank you very much for viewing this entry and I hope you are able to return soon to continue to enjoy more of the site.
Please share your thoughts in the comment section.
Be blessed and enjoy life!