Sei sulla pagina 1di 30

PRACTICAL FILE

FOR
PROGRAMMING IN VISUAL BASIC

SUBMITTED TO: SUBMITTED BY:


Meenu kakker
BCA 5th sem
sec:- ‘A’
Roll no.:-
1. PROGRAM TO DESIGN A USER INTERFACE, WHICH ACCEPT
STUDENT NAME, ROLL_NO, TOTAL MARKS, and PERCENTAGES.

Private Sub Command1_Click ()


Dim MARKS (5) As Double

Dim TOTAL As Double

Text1.Text = Input Box ("ENTER A NAME")

Text2.Text = Input Box ("ENTER A ROLL NO.")

TOTAL = 0

For i = 0 To 4

MARKS(i) = InputBox("ENTER THE MARK")

List3.AddItem (MARKS(i))

TOTAL = TOTAL + MARKS(i)

Next

Text3.Text = TOTAL
Text4.Text = TOTAL / 5

End Sub
OUTPUT:-
2.DESIGN A USER INTERFACE THAT CALCULATE THE SIMPLE INTEREST.
Private Sub Command1_Click()

Dim R As Double

Dim P As Double

Dim T As Double

R=8

If IsNumeric(Text1.Text) Then

P = Val(Text1.Text)

Else

MsgBox ("plz enter a numeric value in text box")

Text1.Text = ""

Text1.SetFocus

Exit Sub

End If

If IsNumeric(Text2.Text) Then

T = Val(Text2.Text)

Else

MsgBox ("plz enter a numeric value in text box")

Text2.Text = ""

Text2.SetFocus

Exit Sub

End If

Text4.Text = (R * P * T) \ 100

End Sub

Private Sub Command2_Click()

Dim R As Double
Dim P As Double

Dim T As Double

R=8

If IsNumeric(Text1.Text) Then

P = Val(Text1.Text)

Else

MsgBox ("plz enter a numeric value in text box")

Text1.Text = ""

Text1.SetFocus

Exit Sub

End If

If IsNumeric(Text2.Text) Then

T = Val(Text2.Text)

Else

MsgBox ("plz enter a numeric value in text box")

Text2.Text = ""

Text2.SetFocus

Exit Sub

End If

Text4.Text = (R * P * T) \ 100

INTEREST = Val(Text4.Text)

Text5.Text = P + INTEREST

End Sub
Private Sub Command3_Click()

Text1.Text = ""

Text2.Text = ""

Text3.Text = ""

Text4.Text = ""

Text5.Text = ""

End Sub
OUTPUT:-
3.Design a user interface to search a no. from given
list by binary search.

Private Sub Command4_Click()


Dim a(20) As Integer

Dim num As Integer, low As Integer, high As Integer

Dim mid As Integer, temp As Integer, n As Integer

Dim flag As Integer

n = InputBox("enter total no. of element for list: ")

flag = 0

For i = 0 To n

a(i) = InputBox("enter your no.:-")

List1.AddItem (a(i))

Next

For i = 0 To n

For j = 0 To n

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 n

List2.AddItem (a(i))

Next

num = InputBox("enter a no. for searching")

Text1.Text = num

low = 0
high = n

While (flag <> 1 And low <= high)

mid = (low + high) / 2

If num < a(mid) Then

high = mid - 1

Else

If num > a(mid) Then

low = mid + 1

Else

If num = a(mid) Then

flag = 1

End If

End If

End If

Wend

If flag = 1 Then

MsgBox ("no is found")

Else

MsgBox ("no. is not found")

End If

End Sub
Output:-
4.Design a user interface to search a no. from given
list by linear search.
Private Sub Command5_Click()

Dim a(20) As Integer

Dim b As Integer, NUM As Integer

NUM = InputBox("enter total no. of element for list: ")

For i = 0 To NUM

a(i) = InputBox("enter your no.:-")

List1.AddItem (a(i))

Next

b = InputBox("enter a no. for searching")

Text1.Text = b

For i = 0 To NUM

If a(i) = b Then

flag = 1

Exit For

End If

Next

If flag = 1 Then

MsgBox ("element is found")

Else

MsgBox ("element is not found")

End If

End Sub
Output:-
5.Design a user interface to sort the given list by
bubble sort.
Private Sub Command7_Click()

Dim a(5) As Integer, n As Integer

n = InputBox("enter total no. of element for list: ")

List1.Clear

For i = 0 To n

a(i) = InputBox("enter a no.")

List1.AddItem (a(i))

Next

For i = n To 0 Step -1

For j = 1 To i

If a(j - 1) > a(j) Then

temp = a(j - 1)

a(j - 1) = a(j)

a(j) = temp

End If

Next j

Next i

MsgBox ("sorted list is:")

List2.Clear

For i = 0 To n

MsgBox (a(i))

List2.AddItem (a(i))

Next

End Sub
Output:-
6.Design a user interface to sort the given list by
selection sort.
Private Sub Command7_Click()

Dim a(5) As Integer, n As Integer

n = InputBox("enter total no. of element for list: ")

List1.Clear

For i = 0 To n

a(i) = InputBox("enter your no.:-")

List1.AddItem (a(i))

Next

For i = 0 To n

For j = 0 To n

If a(i) < a(j) Then

temp = a(i)

a(i) = a(j)

a(j) = temp

End If

Next j

Next i

List2.Clear

For i = 0 To n

MsgBox (a(i))

List2.AddItem (a(i))

Next
Output:-
7.Design a user interface to find the maximum and
minimum no. from the list.
Private Sub Command3_Click()

Dim a(20) As Integer

Dim max As Integer, min As Integer, NUM As Integer

NUM = InputBox("ENTER A NO.:-")

List1.Clear

For I = 0 To NUM

a(I) = InputBox("enter your no.:-")

List1.AddItem (a(I))

Next

max = a(0)

min = a(0)

For I = 0 To NUM

If a(I) > max Then

max = a(I)

End If

If a(I) < min Then

min = a(I)

End If

Next

Text1.Text = max

Text2.Text = min

MsgBox ("maximum no. is:-" & max)

MsgBox ("minimum no. is:-" & min)

End Sub
Output:-
8.design a user interface with 5 label and 5 button for
fontsize,colour,visible.
Private Sub Command1_Click()

Label1.BackColor = vbRed

Label2.BackColor = vbRed

Label3.BackColor = vbRed

Label4.BackColor = vbRed

Label5.BackColor = vbRed

End Sub

Private Sub Command2_Click()

Label1.BackColor = vbBlue

Label2.BackColor = vbBlue

Label3.BackColor = vbBlue

Label4.BackColor = vbBlue

Label5.BackColor = vbBlue

End Sub

Private Sub Command3_Click()

Label1.BackColor = vbGreen

Label2.BackColor = vbGreen

Label3.BackColor = vbGreen

Label4.BackColor = vbGreen

Label5.BackColor = vbGreen

End Sub

Private Sub Command5_Click()


b = InputBox("enter a no. for size")

Label1.FontSize = b

Label2.FontSize = b

Label3.FontSize = b

Label4.FontSize = b

Label5.FontSize = b

End Sub

Private Sub Command6_Click()

a = InputBox("enter true or false for visible")

Label1.Visible = a

Label2.Visible = a

Label3.Visible = a

Label4.Visible = a

Label5.Visible = a

End Sub
Output:-

Potrebbero piacerti anche