Sunteți pe pagina 1din 61

Front End Design Tool VB.

Net

Output

27
Devanshu

03213702014
Front End Design Tool VB.Net

Q15: Draw a Simple Calculator

Design

Coding
Public Class Form2
Dim t1 As Double
Dim sign As String

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
TextBox1.Text = TextBox1.Text & "1"
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button2.Click
TextBox1.Text = TextBox1.Text & "2"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button3.Click
TextBox1.Text = TextBox1.Text & "3"
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button4.Click
TextBox1.Text = TextBox1.Text & "4"
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button5.Click
TextBox1.Text = TextBox1.Text & "5"
28
Devanshu

03213702014
Front End Design Tool VB.Net

End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button6.Click
TextBox1.Text = TextBox1.Text & "6"
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button7.Click
TextBox1.Text = TextBox1.Text & "7"
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button8.Click
TextBox1.Text = TextBox1.Text & "8"
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button9.Click
TextBox1.Text = TextBox1.Text & "9"
End Sub

Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button10.Click
TextBox1.Text = TextBox1.Text & "0"
End Sub

Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button11.Click
If TextBox1.Text.Contains(".") Then
TextBox1.Text = TextBox1.Text
ElseIf TextBox1.Text = "" Then
TextBox1.Text = "0."
Else
TextBox1.Text = TextBox1.Text & "."
End If
End Sub

Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button13.Click
t1 = TextBox1.Text
sign = "+"
TextBox1.Text = ""
End Sub

Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button14.Click
t1 = TextBox1.Text
sign = "-"
TextBox1.Text = ""
End Sub

29
Devanshu

03213702014
Front End Design Tool VB.Net

Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button15.Click
t1 = TextBox1.Text
sign = "*"
TextBox1.Text = ""
End Sub

Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button16.Click
t1 = TextBox1.Text
sign = "/"
TextBox1.Text = ""
End Sub

Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button17.Click
If TextBox1.Text = "" Then
TextBox1.Text = TextBox1.Text
Else
TextBox1.Text = TextBox1.Text.Remove(TextBox1.Text.Length - 1)
End If
End Sub

Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button18.Click
TextBox1.Text = TextBox1.Text * -1
End Sub

Private Sub Button19_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button19.Click
t1 = TextBox1.Text
TextBox1.Text = t1 * 100
End Sub

Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button20.Click
TextBox1.Text = ""
End Sub

Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button12.Click
Dim t2 As Double = TextBox1.Text
Select Case sign
Case "+"
TextBox1.Text = t1 + t2
Case "-"
TextBox1.Text = t1 - t2
Case "*"
TextBox1.Text = t1 * t2
Case "/"
TextBox1.Text = t1 / t2
End Select
End Sub

30
Devanshu

03213702014
Front End Design Tool VB.Net

End Class

Output

31
Devanshu

03213702014
Front End Design Tool VB.Net

Q16: Design a simple application to change the background colors of form in which user enter the
RGB codes.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Me.BackColor = Color.FromArgb(CInt(TextBox1.Text), CInt(TextBox2.Text), CInt(TextBox3.Text))
End Sub
Output

32
Devanshu

03213702014
Front End Design Tool VB.Net

Q17: Write a program to compare three nos and print the largest number among these nos
using if statement

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
If TextBox1.Text > TextBox2.Text And TextBox1.Text > TextBox3.Text Then
MessageBox.Show("The Greatest Number among three is " & TextBox1.Text)
ElseIf TextBox2.Text > TextBox1.Text And TextBox2.Text > TextBox3.Text Then
MessageBox.Show("The Greatest Number among three is " & TextBox2.Text)
ElseIf TextBox3.Text > TextBox2.Text And TextBox3.Text > TextBox1.Text Then
MessageBox.Show("The Greatest Number among three is " & TextBox3.Text)
ElseIf TextBox1.Text = TextBox2.Text And TextBox1.Text = TextBox3.Text Then
MessageBox.Show("All Number are same ")
ElseIf TextBox1.Text = TextBox2.Text Or TextBox2.Text = TextBox3.Text Or TextBox1.Text = TextBox3.Text
Then
MessageBox.Show("Two Number is Same")
End If
End Sub
33
Devanshu

03213702014
Front End Design Tool VB.Net

Output

34
Devanshu

03213702014
Front End Design Tool VB.Net

Q18: Write a program to find out whether a number is prime or not using if statement.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
Dim t As Integer
For i = 2 To (n - 1)
If n Mod i = 0 Then
t = 11
End If
Next
If t = 11 Then
MessageBox.Show("It is Not Prime", "Prime or Not")
Else
MessageBox.Show("It is Prime")
End If
End Sub

35
Devanshu

03213702014
Front End Design Tool VB.Net

Output

36
Devanshu

03213702014
Front End Design Tool VB.Net

Q19: Write a program to print all the Even and Odd numbers between the range given by the
user using if statement.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
Dim t As String = ""
Dim t1 As String = ""
For i = 2 To n Step 2
t=t&i&","
Next
For i = 1 To n Step 2
t1 = t1 & i & " , "
Next
t = t.Remove(t.Length - 2)
t1 = t1.Remove(t1.Length - 2)
MessageBox.Show("Even Numbers Are : " & t)
MessageBox.Show("Odds Numbers Are : " & t1)
37
Devanshu

03213702014
Front End Design Tool VB.Net

End Sub

Output

38
Devanshu

03213702014
Front End Design Tool VB.Net

Q20: Write a program to display the grade obtained by the child according to the marks obtained
by him/her using select case. Criteria for assigning the grades is given below :

If marks are
>=90 - Grade is A
<90 and >=80 Grade is B
<80 and >=70 Grade is C
<70 and >=60 Grade is D
<60 Grade is E

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Double = InputBox("Enter your Marks", "Marks")
Select Case n
Case >= 90
MessageBox.Show("Grade of the Student is A")
Case Is < 90 And n >= 80
MessageBox.Show("Grade of the Student is B")
39
Devanshu

03213702014
Front End Design Tool VB.Net

Case Is < 80 And n >= 70


MessageBox.Show("Grade of the Student is C")
Case Is < 70 And n >= 60
MessageBox.Show("Grade of the Student is D")
Case Is < 60
MessageBox.Show("Gradeof the Student is E")
End Select
End Sub

Output

40
Devanshu

03213702014
Front End Design Tool VB.Net

Q21: Write a program to print table of number given by the user using for.. next.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number ", "Enter a Number")
Dim t As String = ""
For i = 1 To 10
t = t & n & " * " & i & " = " & n * i & vbCrLf
Next
MessageBox.Show(t)
End Sub

41
Devanshu

03213702014
Front End Design Tool VB.Net

Output

42
Devanshu

03213702014
Front End Design Tool VB.Net

Q22: Write a program to print the Fibonacci series with in a given range using for.. next.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a NUmber", "Enter A Number")
Dim t As String = ""
Dim n1 As Integer = 0
Dim n2 As Integer = 1
Dim n3 As Integer = 0
For i = 1 To n
t = t & n1 & " , "
n1 = n2 + n3
n2 = n3

43
Devanshu

03213702014
Front End Design Tool VB.Net

n3 = n1
Next
t = t.Remove(t.Length - 2)
MessageBox.Show(t)
End Sub

Output

44
Devanshu

03213702014
Front End Design Tool VB.Net

Q23: Write a program to display following series:


a. 1,3,5,7,9,.15
b. 0.2,0.4,0.6,,2.0
c. 15,13,11,9,7,.1
d. 10, 5, 0,-5,-10...

Design

45
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
Dim t As String = ""
Select Case n
Case 1
For i = 1 To 15 Step 2
t=t&i&","
Next
t = t.Remove(t.Length - 2)
MessageBox.Show(t)
Case 2
For i = 0.2 To 2.0 Step 0.2
t=t&i&","
Next
t = t.Remove(t.Length - 2)
MessageBox.Show(t)
Case 3
For i = 15 To 1 Step -2
t=t&i&","
Next
t = t.Remove(t.Length - 2)
MessageBox.Show(t)
Case 4
For i = 10 To -15 Step -5
t=t&i&","
Next
t = t.Remove(t.Length - 2)
MessageBox.Show(t)
End Select
End Sub

46
Devanshu

03213702014
Front End Design Tool VB.Net

Output

47
Devanshu

03213702014
Front End Design Tool VB.Net

Q24: Write a program to print the following patterns:-


1. *
***
*****
*******
Design

48
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim r As Integer = CInt(TextBox1.Text)
Dim i, j As Integer
Dim str As String = ""

i=1
While (i <= r)
j=1
While (j <= ((r - i)))
str = str & " "
j=j+1
End While
j=1
While (j <= (i * 2 - 1))
str = str & "*"
j=j+1
End While
str = str & " " & vbCrLf
i=i+1
End While
MessageBox.Show(str)

End Sub
End Class

Output

49
Devanshu

03213702014
Front End Design Tool VB.Net

2. A
AB
AB C
AB C D

Design

50
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim t As String = ""
Dim t1 As String = ""
Dim t2 As String = ""
Dim t3 As String = ""
For i = 4 To 0 Step -1
t=t&""
Next
For j = 3 To 0 Step -1
t1 = t1 & " "
Next
For j = 2 To 0 Step -1
t2 = t2 & " "
Next
For j = 1 To 0 Step -1
t3 = t3 & " "
Next
MessageBox.Show(t & "A" & vbCrLf & t1 & "AB" & vbCrLf & t2 & "ABC" & vbCrLf & t3 & "ABCD")
End Sub

Output

51
Devanshu

03213702014
Front End Design Tool VB.Net

Q25: Create an Application to set Text Background Color Fore Color ,Font and Height properties
of a Textbox using With Statement.

Design

52
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
With TextBox1
.BackColor = Color.Cyan
.ForeColor = Color.Gray
.Font = New Font("Times New Roman", 22, FontStyle.Bold)
End With
End Sub

Output

53
Devanshu

03213702014
Front End Design Tool VB.Net

54
Devanshu

03213702014
Front End Design Tool VB.Net

Q26: Using For_ Each_ Next Loop change the fore color of all the labels in a form.
Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim lb As Control
For Each lb In Controls
If TypeOf lb Is Label Then
lb.ForeColor = Color.Green
End If
Next
End Sub

55
Devanshu

03213702014
Front End Design Tool VB.Net

Output

56
Devanshu

03213702014
Front End Design Tool VB.Net

Q27: Write a program to check whether an entered number is Armstrong or not using do
while..loop.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
Dim t As Integer
Dim t1 As Integer
Dim t2 As Integer = 0
t=n
Do While (t <> 0)
t1 = t Mod 10
t = t \ 10
t2 = t2 + Math.Pow(t1, 3)
Loop
If t2 = n Then
MessageBox.Show("The Number is Armstrong")
Else
MessageBox.Show("The Number is not Armstrong")
End If
End Sub

57
Devanshu

03213702014
Front End Design Tool VB.Net

Output

58
Devanshu

03213702014
Front End Design Tool VB.Net

Q28: Write a program to check whether an entered string is Palindrome or not using do
while..loop.

Design

Coding
Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click

Dim st As String = ""


Dim s As String = ""
Dim a As Integer

st = InputBox(",")
a = Len(st)

While (a >= 1)
s = s & Mid(st, a, 1)
a=a-1

End While
If st = "" Then
MessageBox.Show("Enter a String")
ElseIf st = s Then
MessageBox.Show(st & " Is Palindrome")

59
Devanshu

03213702014
Front End Design Tool VB.Net

Else
MessageBox.Show(st & " Is Not Palindrome")
End If
End Sub
End Class

Output

60
Devanshu

03213702014
Front End Design Tool VB.Net

Q29: Write a program to find factorial of a number using Do Until..Loop.

Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
Dim t As Integer = n - 1
Dim t1 As Integer = n
Do Until (t = 1)
n=n*t
t=t-1
Loop
MessageBox.Show("Factorial of the Number " & t1 & " is " & n)
End Sub

61
Devanshu

03213702014
Front End Design Tool VB.Net

Output

62
Devanshu

03213702014
Front End Design Tool VB.Net

Q30: Create an Array with 10 elements as entered by the user and search the number asked by
the user and display its position.

Design

Coding
Dim a(9) As Integer

Private Sub Form8_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


MyBase.Load
Dim t As String = ""
For i = 0 To 9
a(i) = InputBox("Enter the Number of Array", "Enter the Number")
t = t & a(i) & " , "
Next
t = t.Remove(t.Length - 2)
Label2.Text = "Array : " & t
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
Dim n As Integer = InputBox("Enter a Number", "Enter a Number")
63
Devanshu

03213702014
Front End Design Tool VB.Net

Dim t1 As Integer = 0
Dim t2 As Integer
For Each item In a
t1 = t1 + 1
If item = n Then
t2 = 10
Exit For
End If
Next
If t2 = 10 Then
MessageBox.Show("The Position of Number " & n & " is " & t1)
Else
MessageBox.Show("The Number " & n & " is not in Array")
End If
End Sub
Output

64
Devanshu

03213702014
Front End Design Tool VB.Net

Q31: Create an Array with 10 elements and arrange it in ascending order.

Design

Coding
Dim a(5) As Integer
Private Sub Form9_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim t As String = ""
For i = 0 To 5
a(i) = InputBox("Enter the Number of Array", "Enter the Number")
t = t & a(i) & " , "
Next
t = t.Remove(t.Length - 2)
Label2.Text = "Array : " & t
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
65
Devanshu

03213702014
Front End Design Tool VB.Net

Dim t1 As String = ""


Array.Sort(a)
For i = 0 To 5
t1 = t1 & a(i) & " , "
Next
t1 = t1.Remove(t1.Length - 2)
Label3.Text = Label3.Text & t1
End Sub

Output

66
Devanshu

03213702014
Front End Design Tool VB.Net

Q32: Create a Menu driven application to show Matrix Addition, Subtraction and Multiplication.
Also give the user the option to exit from the application.
Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim m1(0 To 2, 0 To 2) As Integer
Dim m2(0 To 2, 0 To 2) As Integer
Dim m3(0 To 2, 0 To 2) As Integer
Dim n As Integer = TextBox1.Text
Dim stra As String = ""
Dim stra1 As String = ""
Dim stra2 As String = ""
67
Devanshu

03213702014
Front End Design Tool VB.Net

For i = 0 To 2
For j = 0 To 2
m1(i, j) = InputBox("Enter Element No : 1", "First Matrix")
stra = stra & m1(i, j) & " "
Next
stra = stra & vbCrLf
Next
For i = 0 To 2
For j = 0 To 2
m2(i, j) = InputBox("Enter Element No : 1", "Second Matrix")
stra1 = stra1 & m2(i, j) & " "
Next
stra1 = stra1 & vbCrLf
Next
MessageBox.Show(stra, "First Matrix")
MessageBox.Show(stra1, "Second Matrix")
Select Case n
Case 1
For i = 0 To 2
For j = 0 To 2
m3(i, j) = m1(i, j) + m2(i, j)
stra2 = stra2 & m3(i, j) & " "
Next
stra2 = stra2 & vbCrLf
Next
MessageBox.Show(stra2, "Sum of Matrix ")
Case 2
For i = 0 To 2
For j = 0 To 2
m3(i, j) = m1(i, j) - m2(i, j)
stra2 = stra2 & m3(i, j) & " "
Next
stra2 = stra2 & vbCrLf
Next
MessageBox.Show(stra2, "Subtraction of Matrix ")
Case 3
For i = 0 To 2
For j = 0 To 2
m3(i, j) = 0
For k = 0 To 2
m3(i, j) = m3(i, j) + m1(i, k) * m2(k, j)
Next
stra2 = stra2 & m3(i, j) & " "
Next
stra2 = stra2 & vbCrLf
Next
MessageBox.Show(stra2, "Product of Matrix ")
End Select
End Sub

68
Devanshu

03213702014
Front End Design Tool VB.Net

Output

69
Devanshu

03213702014
Front End Design Tool VB.Net

Q33: Write a program to show the usage of all string functions.

Design

Coding

70
Devanshu

03213702014
Front End Design Tool VB.Net

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The length of " & n & " is : " & n.Length, "Length")
End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button4.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The Reverse of " & n & " is : " & StrReverse(n), "Reverse")
End Sub

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button6.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The string after trim is " & Trim(n), "Trim")
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button3.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
Dim t As String = InputBox("Enter a Character to be Replaced")
MessageBox.Show("Befor Replace String : " & n & vbCrLf & "String after Replace " & n.Replace(t, "#"),
"Replace")
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button7.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The string after Rtrim is " & RTrim(n), "Rtirm")
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button8.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The string in Lower string is : " & n.ToLower, "Lower")
End Sub

Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button9.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
MessageBox.Show("The string in Lower string is : " & n.ToUpper, "Upper")
End Sub

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button5.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
Dim t1 As Integer = InputBox("Enter the First Position", "Enter a Number")
Dim t2 As Integer = InputBox("Enter the Second Position", "Enter a Number")
MessageBox.Show("The Substring of " & n & " from " & t1 & " to " & t2 & " is " & n.Substring(t1 - 1, t2 -
1), "Substring")
End Sub

71
Devanshu

03213702014
Front End Design Tool VB.Net

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button2.Click
Dim n As String = InputBox("Enter a String", "Enter a String")
Dim t1 As String = InputBox("Enter a String", "Enter a String")
If (StrComp(n, t1) = 0) Then
MessageBox.Show("The Strings are Same", "Compare")
Else
MessageBox.Show("The Strings are Different", "Compare")
End If
End Sub
Output

Q34: Create a jagged Array with 3 rows and initializes each row with the elements print in the
window.
Design

72
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Public Class Form2

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
Dim str As String = ""
For a = 0 To 3
Dim arr(a) As Integer
Next
Dim jag(2)() As Integer
jag(0) = New Integer() {1, 2, 3}
jag(1) = New Integer() {0}
jag(2) = New Integer() {1, 2, 3, 4}
Dim i, j As Integer
For i = 0 To jag.Length - 1
Dim innerarray As Integer() = jag(i)

For j = 0 To innerarray.Length - 1
str = str & innerarray(j)
Next
str = str & vbCrLf
Next
Label1.Text = str
End Sub
End Class

Output

73
Devanshu

03213702014
Front End Design Tool VB.Net

Q35: Write a program to create simple array list and perform various operations of array list.
Design

74
Devanshu

03213702014
Front End Design Tool VB.Net

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim al As New ArrayList
Dim str As String = ""
Dim c As Integer = TextBox1.Text
Dim t1 As Integer
Dim t2 As Integer
Dim t3 As Integer
Dim t4 As Integer
al.Add(5)
al.Add(8)
al.Add(9)
Select Case c
Case 1
t1 = InputBox("Enter a Number to Add", "Enter a Number")
al.Add(t1)
For Each item In al
str = str & item & " , "
Next
str = str.Remove(str.Length - 2)
MessageBox.Show(str, "Array")
Case 2
t2 = InputBox("Enter a Number to Add", "Enter a Number")
t3 = InputBox("Enter the position from which the Element is to Changed", "Enter the Number")
al.Insert(t3 - 1, t2)
For Each item In al
str = str & item & " , "
Next
str = str.Remove(str.Length - 2)
MessageBox.Show(str, "Array")
Case 3
t4 = InputBox("Enter the position from which the Element is to Deleted", "Enter the Number")
75
Devanshu

03213702014
Front End Design Tool VB.Net

al.RemoveAt(t4 - 1)
For Each item In al
str = str & item & " , "
Next
str = str.Remove(str.Length - 2)
MessageBox.Show(str, "Array")
Case 4
al.Sort()
For Each item In al
str = str & item & " , "
Next
str = str.Remove(str.Length - 2)
MessageBox.Show(str, "Array")
End Select

Output

Q36: Create a structure for storing book details and populate it with data.
76
Devanshu

03213702014
Front End Design Tool VB.Net

Design

Coding
Structure bd
Dim id As Integer
Dim bn As String
Dim an As String

End Structure

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
Dim t As New bd
t.id = InputBox("Enter Book ID:", "Enter Book ID")
t.bn = InputBox("Enter Book Name:", "Enter Book Name")
t.an = InputBox("Enter Author Name:", "Enter Author Name")
Dim str As String = ""
str = str & "Book ID : " & t.id & vbCrLf & "Book Name : " & t.bn & vbCrLf & "Author Name : " & t.an
MessageBox.Show(str, "Boook Details")
End Sub

Output
77
Devanshu

03213702014
Front End Design Tool VB.Net

78
Devanshu

03213702014
Front End Design Tool VB.Net

Q37: Create an enumeration named Designation & takes 5 Designations in it -: Manager, Asst
Manager, Project Manager, Team Lead and Developer. Initialize salaries for these posts in the
enumerator & display it in TextBox.
Design

Coding
Public Class Form3

Enum salary
manager = 230000
ceo = 1000000
ast_manager = 150000
Project_manager = 200000
developer = 700000
team_lead = 900000
End Enum

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
If TextBox1.Text = "ceo" Then
TextBox2.Text = salary.ceo
ElseIf TextBox1.Text = "manager" Then
TextBox2.Text = salary.manager
ElseIf TextBox1.Text = "Asst manager" Then
TextBox2.Text = salary.ast_manager
ElseIf TextBox1.Text = "Project manager" Then
TextBox2.Text = salary.Project_manager
ElseIf TextBox1.Text = "developer" Then
TextBox2.Text = salary.developer
ElseIf TextBox1.Text = "team lead" Then
TextBox2.Text = salary.team_lead
79
Devanshu

03213702014
Front End Design Tool VB.Net

End If
End Sub
End Class

Output

80
Devanshu

03213702014
Front End Design Tool VB.Net

Q38: To generate prime number for a given range using function.


Design

Coding
Public Class Form4

Sub CheckPrime(ByVal a As Integer, ByVal b As Integer)


Dim string1 As String = ""
Dim flag As Boolean = True
For i = a To b
For j = 2 To i / 2
If i Mod j = 0 Then
flag = False
Exit For
Else
flag = True
End If
Next
If flag = True Then
string1 = string1 & i & ", "
End If
Next
MessageBox.Show(string1)
End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles


Button1.Click
Me.CheckPrime(Val(TextBox1.Text), CInt(TextBox2.Text))
End Sub
81
Devanshu

03213702014
Front End Design Tool VB.Net

End Class

Output

82
Devanshu

03213702014
Front End Design Tool VB.Net

Q39: To find the Fibonacci series with in a given range with the help of procedure.
Design

Coding
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
Dim f = CInt(TextBox1.Text)
Dim l = CInt(TextBox2.Text)
Dim t = 0
Dim t1 = 0
Dim t2 = 1
Dim str = ""
For i = f To l
t = f + t2
f = t2
t2 = t
If t2 > l Then
Exit For
End If
str = str & t & " , "
Next
str = str.Remove(str.Length - 2)
MessageBox.Show(str, "Fibonnaci Series")
83
Devanshu

03213702014
Front End Design Tool VB.Net

End Sub

Output

84
Devanshu

03213702014
Front End Design Tool VB.Net

Q40: Write a program to differentiate between parameter passing (ByVal and ByRef).
Design

Coding
Function sw(ByRef t1 As Integer, ByRef t2 As Integer) As Integer
Dim t3 As Integer
Dim str As String = ""
t3 = t1
t1 = t2
t2 = t3
str = str & "First Number = " & t1 & vbCrLf & "Second Number = " & t2
Return Nothing
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
MessageBox.Show("First Number = " & TextBox1.Text & vbCrLf & "Second Number = " & TextBox2.Text,
"ByVal")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Dim t As String
t = sw(CInt(TextBox1.Text), CInt(TextBox2.Text))
85
Devanshu

03213702014
Front End Design Tool VB.Net

MessageBox.Show(t, "ByRef")
End Sub

Output

86
Devanshu

03213702014
Front End Design Tool VB.Net

87
Devanshu

03213702014

S-ar putea să vă placă și