You are on page 1of 6

PRACTICAL-3

1. Aim: Write a Program in VB to accept Numbers from user (in textbox) and perform all
arithmetic operation on that numbers.

2. Theory/Logic: Here two numbers are entered by user and user can perform all arithmetic
operations i.e addition, substraction, multiplication, division, square, squareroot etc. For an
example if we want to multiply two numbers then first enter both numbers and then click on
the command button showing multiplication. And we will get the desired output.

The controls which are used in project are listed below with respective properties.

Object Properties Value


Label1 Name lblNum1
Caption Enter 1st Number
Alignment 2-Center
Font Size 14
Textbox1 Name txtNum1
Alignment 2-Center
Font Size 20
Label2 Name lblNum2
Caption Enter 2nd No.
Alignment 2-Center
Font Size 14
TextBox2 Name txtNum2
Alignment 2-Center
Font Size 20
Command1 Name Command1
Caption Addtion
Font Size 14
ToolTipText to add the numbers
Command2 Name Command2
Caption Substraction
Font Size 14
ToolTipText to substract the numbers
Command3 Name Command3
Caption Multiplication
Font Size 14
ToolTipText to multiply the numbers
Command4 Name Command4
Caption Division
Font Size 14
ToolTipText to divide the number
Command5 Name Command5
Caption Power
Font Size 14
ToolTipText To find power of
number
Command6 Name Command6
Caption Square
Font Size 14
ToolTipText To find square of
number
Command7 Name Command7
Caption Squareroot
Font Size 14
ToolTipText To find squareroot of the
number
Label4 Name Label4
Alignment 2-center
Caption Answer

Program Code:

Private Sub Command1_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = " Addition is " & a + b

End Sub

Private Sub Command2_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = "Substraction is " & a - b

End Sub

Private Sub Command3_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = "Multiplication is " & a * b


End Sub

Private Sub Command4_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = " Division is " & a / b

End Sub

Private Sub Command5_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = "Ans is " & a ^ b

End Sub

Private Sub Command6_Click()

a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = "square of " & a & " is " & a * a

End Sub

Private Sub Command7_Click()


a = Val(Text1.Text)

b = Val(Text2.Text)

Label4.Caption = "Square Root of " & a & " is " & Sqr(a)

End Sub

Output:

You might also like