Tuesday, October 5, 2010

Example for Operators

Page : 1 2 3 4 5 6 7 8 9 10 11 12 13 14
Example

Form Design

Place the 3 Lebel, 3 TextBox and 7 Button in your Form using ToolBox
Change the Properties of the Label to the following
Text: Number1
Text: Number2
Text: Result
Change the Properties of the Textbox to the following
Name: TxtNumber1Text: just delete the default Textbox1, and leave the textbox blank
Name: TxtNumber2Text: just delete the default Textbox2, and leave the textbox blank
Name: TxtResultText: just delete the default Textbox3, and leave the textbox blank
Change the Properties of the Button to the following:
Name: AddButtText: just delete the default Button1, and Type Add
Name: AddSubText: just delete the default Button2, and Type Sub
Name: MulButtText: just delete the default Button3, and Type Mul
Name: DivButtText: just delete the default Button4, and Type Div
Name: IntDivButtText: just delete the default Button5, and Type IntDivision
Name: ModButtText: just delete the default Button6, and Type Mod
Your Form should look like this:





Source Code

Private Sub AddButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AddButt.Click


TxtResult.Text = Val(TxtNumber1.Text) + Val(TxtNumber2.Text)


End Sub

Private Sub MulButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MulButt.Click


TxtResult.Text = Val(TxtNumber1.Text) * Val(TxtNumber2.Text)


End Sub

Private Sub DivButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DivButt.Click


TxtResult.Text = Val(TxtNumber1.Text) / Val(TxtNumber2.Text)

End Sub

Private Sub ModButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModButt.Click
TxtResult.Text = Val(TxtNumber1.Text) Mod Val(TxtNumber2.Text)
End Sub
1


Private Sub SubButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SubButt.Click

TxtResult.Text = Val(TxtNumber1.Text) - Val(TxtNumber2.Text)

End Sub

Private Sub ExpoButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExpoButt.Click


TxtResult.Text = Val(TxtNumber1.Text) ^ Val(TxtNumber2.Text)

End Sub

Private Sub IntDivButt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles IntDivButt.Click


TxtResult.Text = Val(TxtNumber1.Text) \ Val(TxtNumber2.Text)

End Sub

End Class

Output