27 April, 2011

Procedure



1.            Calculate the sum/average of two numbers using a sub procedure.

Call sum()
End Sub
Sub sum()
Dim a As Integer = 2
Dim b As Integer = 3
TextBox1.Text = (a + b) / 2
End Sub


2.            Determine whether a number is even or odd using a sub procedure.

Call check()
End Sub
Sub check()
Dim a As Integer = TextBox1.Text
If a Mod 2 = 0 Then
TextBox2.Text = "even"
Else : TextBox2.Text = "ODD"
End If
End Sub


3.            Calculate the Area of a rectangle/square/triangle/circle using a sub procedure.

Call area()
End Sub
Sub area()
Dim a As Integer = TextBox1.Text
Dim b As Integer = TextBox2.Text
TextBox3.Text = a * b
TextBox4.Text = a * a
TextBox5.Text = 0.5 * a * b
TextBox6.Text = 3.1416 * a * a
End Sub


4.            Determine whether a company has made Profit or Loss from Cost and Revenue of the company using a sub procedure.

Call Check()
End Sub
Sub check()
Dim a As Integer = TextBox1.Text
Dim b As Integer = TextBox2.Text
If a > b Then
TextBox3.Text = "Profit"
Else : TextBox3.Text = "Loss"
End If
End Sub


5.            Calculate the factorial of a number using a sub procedure.

Call factorial()
End Sub
Sub factorial()
Dim i As Integer = 1
Dim output As Integer = 1
Do While i <= TextBox1.Text
output = output * i
i = i + 1
Loop
End Sub


6.            Determine a person’s first name from his/her full name using a sub procedure.       [Hint: Use space(“ ”) to separate the first name and last name]

Call Main()
End Sub
Sub Main()
Dim s1 As String = "Zulfekar"
Dim s2 As String = "Shumon"
TextBox3.Text = s1 & s2
End Sub

0 comments:

Post a Comment