You are on page 1of 17

Question 1 WAP to calculate the factorial of any number

(a) using function


(b) using sub procedure

1 (a) Dim I, F As Variant


Public Function Fact(ByVal N As Variant) As Variant
F=1
For I = 1 To N
F=F*I
Next I
Fact=f
End Function

Private Sub Command1_Click()


N = InputBox("Enter the Number")
F = Fact(N)
MsgBox ("Factorial of " & N & " is " & F & ".")
End Sub
1 (b) using Sub procedure
Dim I, F As Variant
Private Sub Fact(ByVal N As Variant) As Variant
F=1
For I = 1 To N
F=F*I
Next I
MsgBox ("Factorial of " & N & " is " & F & ".")
End Sub

Private Sub Command2_Click()


N = InputBox("Enter the Number")
F = Fact(N)
End Sub

Question 2 WAP to print the sum of event numbers


between ranges
Option Explicit
Private Sub Command1_Click()
Dim Sum As Integer
Dim Lower, Upper, I As Integer
Lower = Val(Text1.Text)
Upper = Val(Text2.Text)
For I = Lower To Upper Step 1
If I Mod 2 = 0 Then
Sum = Sum + I
End If
Next i
Text3.Text = "The Sum of Even Numbers are " & Sum
End Sub

Question 3 WAP to print the greatest of three numbers


(a) using function
(b) without function

3(a)
Public Function Greatest(ByVal a As Integer, ByVal b As Integer, ByVal c As Integer)
If a > b And a > c Then
Greatest=a
ElseIf b > c And b > a Then
Greatest=b
ElseIf c > a And c > b Then
Greatest=c
End If
End Function

Private Sub Command1_Click()


Dim a As Integer
Dim b As Integer
Dim c As Integer
a = InputBox("ENTER THE FIRST NUMBER")
b = InputBox("ENTER THE SECOND NUMBER")
c = InputBox("ENTER THE THIRD NUMBER")
g=Greatest(a, b, c)
MsgBox(“Greatest of three nos. is “&g)
End Sub

3 (b)
Dim a, b, c As Integer
Private Sub Command1_Click()
a = InputBox("ENTER THE FIRST NUMBER")
b = InputBox("ENTER THE SECOND NUMBER")
c = InputBox("ENTER THE THIRD NUMBER")
If a > b And a > c Then
MsgBox "The Greatest Number is A."
ElseIf b > c And b > a Then
MsgBox "The Greatest Number is B."
ElseIf c > a And c > b Then
MsgBox "The Greatest Number is C."
End If
End Sub

Question 4 WAP to swap the numbers or text


(a) using function/sub
procedure
(b) using event procedure
(a)
Public Sub swap(n As TextBox, m As TextBox)
Dim temp As Variant
temp = n
n.Text = m.Text
m.Text = temp
End Sub

Private Sub Command1_Click()


Call form1.swap(Text1, Text2)
End Sub

(b)
Private Sub Command1_Click()
Dim I As Variant
I = Text1.Text
Text1.Text = Text2.Text
Text2.Text = I
End Sub

Question 5 WAP to calculate the simple interest using


(a) Function
(b) Sub procedure

Public Function SI(ByVal P As Integer, ByVal R As


Integer, ByVal T As Integer) As Integer
SI = P * R * T / 100
End Function

Private Sub Command1_Click()


Dim P1 As Integer
Dim R1 As Integer
Dim T1 As Integer
P1 = Val(Text1.Text)
R1 = Val(Text2.Text)
T1= Val(Text3.Text)
a = SI(P1, R1, T1)
MsgBox ("Simple Interest = " & a)
End Sub

5 (b)

Private Sub Simple(ByVal P As Integer, ByVal R As Integer, ByVal T As Integer) As


Integer
Dim SI as single
SI = P * R * T / 100
MsgBox ("Simple Interest = " & SI)
End Sub

Private Sub Command1_Click()


Dim P1, R1, T1, SI As Single
P1 = Val(Text1.Text)
R1 = Val(Text2.Text)
T1 = Val(Text3.Text)
Call Simple(P1,R1,T1)
End Sub

Question 6 WAP to print the area of a triangle using


function

Public Function AOT(ByVal H As Integer, ByVal b As Integer) As Integer


AOT = 1 / 2 * (H * b)
End Function

Private Sub Command3_Click()


Dim H1, b1, C1 As Integer
H1 = Val(Text6.Text)
B1 = Val(Text1.Text)
C1 = AOT(H1, B1)
MsgBox ("Area of the Triangle " & c1)
End Sub

Question 7 WAP to check whether the number is prime or


not

Dim I, Num As Integer


Dim flag As Boolean
Private Sub Command1_Click()
num = InputBox("Enter the Number")
For i = 2 To num - 1
If num Mod i = 0 Then
flag = True
End If
Next i
If flag = True Then
MsgBox (num & " is not a Prime Number.")
Else
MsgBox (num & " is a Prime Number.")
End If
flag = False
End Sub
Or you can do

Dim I, Num As Integer


Dim fact As Integer
Private Sub Command1_Click()
num = InputBox("Enter the Number")
fact=0
For i = 2 To num - 1
If num Mod i = 0 Then
Fact=fact+1
End If
Next i
If fact=0 Then
MsgBox (num & " is a Prime Number.")
Else
MsgBox (num & " is no a Prime Number.")
End If
End Sub

Question 7(a) WAP to find the prime numbers between


range
Dim I, Num As Integer
Dim start, end, fact As Integer
Private Sub Command1_Click()
start= InputBox("Enter the starting Number")
end = InputBox("Enter the ending Number")
For num=start to end
fact=0
For i = 2 To num - 1
If num Mod i = 0 Then
Fact=fact+1
End If
Next i
If fact=0 Then
MsgBox (num & " is a Prime Number.")
Else
MsgBox (num & " is no a Prime Number.")
End If
Next num
End Sub

Question 8 WAP to print the Fibonacci series


(1,1,2,3,5,8,13,….)

Private Sub Command1_Click()


Dim x As Integer, y As Integer, temp As Integer
' first terms in the fibonacci series
x=1
y=1
Form12.Cls
Print "Fibonacci Series : "
Print
Print x;
Print
Do While y <= 100
Print y;
temp = x + y
x=y
y = temp
Print
Loop
End Sub

Or
Dim A(20) as Integer
Private Sub Command3_Click()
A(0)=0
A(1)=1
For I =2 to 19
A(I)=a(I -1)+a(I -2)
Next I
For I =0 to 19
Print A(I)& Space(3);
Next I
End Sub

Question 9 WAP to print the sum of two matrix

Dim A(1 To 3, 1 To 3) As Integer


Dim B(1 To 3, 1 To 3) As Integer
Dim Sum(1 To 3, 1 To 3) As Integer

Private Sub Command1_Click()


For i = 1 To 3
For J = 1 To 3
A(i, J) = InputBox("A Array Element no Row=" & i & " , " & "Col=" & J)
Next J
Next i
For i = 1 To 3
For J = 1 To 3
B(i, J) = InputBox("B Array Element no Row=" & i & "Col=" & J)
Next J
Next i
For i = 1 To 3
For J = 1 To 3
Sum(i, J) = A(i, J) + B(i, J)
Next J
Next i
Print "---The Array Sum is ----"
Print
For i = 1 To 3
For J = 1 To 3
Print Sum(i, J) & Space(2);
Next J
Print
Next i
End Sub

Question 10 WAP to print the diagonal elements of a


matrix and their sum

Dim a(1 To 3, 1 To 3) As Integer


Dim Sum As Variant

Private Sub Command1_Click()


Print "Diagonal Elements are"
For I = 1 To 3
For J = 1 To 3
a(I, J) = InputBox("Element No. Rows = " & I & "Column = " & J)
If I = J Then
Print a(I, J) & Space(2);
End If
Next J
Print
Next I
End Sub
Private Sub Command2_Click()
For I = 1 To 3
For J = 1 To 3
If I = J Then
Sum = Sum + a(I, J)
End If
Next J
Next I
MsgBox ("The sum of the Diagonal Elements is " & Sum & ".")
End Sub

Question 11 WAP to print the multiplication of two matrix

Dim A(1 To 3, 1 To 3) As Integer


Dim B(1 To 3, 1 To 3) As Integer
Dim Prod(1 To 3, 1 To 3) As Integer

Private Sub Command1_Click()


For i = 1 To 3
For J = 1 To 3
A(i, J) = InputBox("A Array Element no Row=" & i & " , " & "Col=" & J)
Next J
Next i

For i = 1 To 3
For J = 1 To 3
B(i, J) = InputBox("B Array Element no Row=" & i & "Col=" & J)
Next J
Next i

For i = 1 To 3
For J = 1 To 3
For k = 1 To 3
Prod(i, J) = Prod(i, J) + A(i, k) * B(k, J)
Next k
Next J
Next i

Print "---The Product of array is ----"


For i = 1 To 3
For J = 1 To 3
Print Prod(i, J) & Space(2);
Next J
Print
Next i
End Sub

Question 12 WAP to create control array at design time


and run time and sort the elements
At Run time:
Dim Total As Integer
Dim Temp
Private Sub Command1_Click()
Load Text1(Text1.UBound + 1)
Text1(Text1.UBound).Top =
Text1(Text1.UBound - 1).Top + 600
Text1(Text1.UBound).Visible = True
Total = Total + 1
End Sub
Private Sub Command3_Click()
For I = 0 To Text1.UBound
Text1(I) = ""
Next I
End Sub

Private Sub Command4_Click()


For I = 0 To Text1.UBound
For J = I + 1 To Text1.UBound
If Val(Text1(I)) > Val(Text1(J)) Then
Temp = Text1(I)
Text1(I) = Text1(J)
Text1(J) = Temp
End If
Next J
Next I
End Sub
At Design time:
Private Sub Command5_Click()
For i=0 to 9
A(i)=val (Text(i))
Next i
For I = 0 To 9
For J = I + 1 To 9
If a(I) < a(J)) Then
Temp = a(I)
a(I) = a(J)
a(J) = Temp
End If
Next J
Next I
For I =0 to 9
Text(I)=a(I)
Next I
End Sub

Question 13 WAP to get the items in the two lists and


display in the third list after concatenation of the items
shown in the both the list box
Private Sub Combination_Click()
List3.AddItem (List1.List(List1.ListIndex)) & (List2.List(List2.ListIndex))
End Sub

Private Sub Form_Load()


List1.AddItem "Jammu & Kashmir"
List1.AddItem "Haryana"
List1.AddItem "Delhi"
List1.AddItem "Uttar Pradesh"
List1.AddItem "Maharashtra"

List2.AddItem "Srinagar"
List2.AddItem "Chandigarh"
List2.AddItem "Delhi"
List2.AddItem "Lucknow"
List2.AddItem "Mumbai"
End Sub

Question 14 WAP to get the string and check whether it is


palindrome or not (i.e Madam,Malyalam,etc)

Private Sub Command1_Click()


a = Text1.Text
b = StrReverse(a)
result = StrComp(a, b, vbTextCompare)
If result = 0 Then
MsgBox(a & " is a palindrome...")
Else
MsgBox(a & " is not a palindrome...")
End If
End Sub

Question 15 WAP to print the calculator without using


control array
Dim a, b, c As Integer
Private Sub CmdAdd_Click(Index As Integer)
a = Val(TxtOne.Text)
b = Val(TxtTwo.Text)
c=a+b
TxtResult.Text = Val(c)
End Sub

Private Sub
CmdMinus_Click(Index As
Integer)
a = Val(TxtOne.Text)
b = Val(TxtTwo.Text)
c=a-b
TxtResult.Text = Val(c)
End Sub

Private Sub CmdMultiply_Click()


a = Val(TxtOne.Text)
b = Val(TxtTwo.Text)
c=a*b
TxtResult.Text = Val(c)
End Sub

Private Sub CmdDivide_Click()


a = Val(TxtOne.Text)
b = Val(TxtTwo.Text)
c=a/b
TxtResult.Text = Val(c)
End Sub

Private Sub CmdExit_Click()


End
End Sub

Question 16 WAP to print the reverse the digits


Dim a, b As Integer
Private Sub Command1_Click()
a = Val(Text1.Text)
b = Val(Text2.Text)
b = StrReverse(a)
Text2.Text = b
End Sub

Question 17 WAP to print whether the character is vowel


or consonant.
Dim Ch As Variant
Private Sub Command1_Click()
Ch = InputBox("Enter a Character")
If (Ch = "A" Or Ch = "a" Or Ch = "E" Or Ch = "e" Or Ch = "i" Or Ch = "I" Or Ch
= "O" Or Ch = "o") Then
MsgBox (Ch & " is a vowel.")
Else
MsgBox (Ch & " is not a vowel.")
End If
End Sub

Question 18 WAP to print the digits into words


Private Sub Command1_Click()
N = InputBox("Enter digit")
Select Case N
Case 0
Text1.Text = "Zero"
Case 1
Text1.Text = "One"
Case 2
Text1.Text = "Two"
Case 3
Text1.Text = "Three"
Case 4
Text1.Text = "Four"
End Select
End Sub

Question 19 WAP to calculate the power of a number using


module and static function

Using Module :
Public Function power(n As Integer, e As Integer) As Long
Dim res As Long
power = n ^ e
End Function

Public Function counter() As Integer


Static ntimes As Byte
ntimes = ntimes + 1
counter = ntimes
End Function

Private Sub cmdmodule_Click()


txtres.Text = modpower.power(txtno1.Text, txtno2.Text)
End Sub

Private Sub cmdstatic_Click()


Dim str As String
str = "Button pressed " & modcounter.counter()
cmdstatic.Caption = str
End Sub
Private Sub cmdcancel_Click()
End
End Sub