0% found this document useful (0 votes)
209 views26 pages

Khushi VB

This document provides code snippets in Visual Basic to create various applications. Some key examples include: 1. Creating an application that displays an image when a command button is clicked, and resizes the image over time using a timer control. 2. Checking if a number is even or odd, calculating factorials, and determining if a number is prime. 3. Calculating book discounts based on number of books purchased. 4. Creating forms to display student names in list boxes and allow shifting between lists, as well as displaying state capitals and cities based on combo box selection. 5. Creating arrays, finding frequencies of elements, and displaying positions. Also counting characters and words in a text

Uploaded by

Khushi Aglawe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
209 views26 pages

Khushi VB

This document provides code snippets in Visual Basic to create various applications. Some key examples include: 1. Creating an application that displays an image when a command button is clicked, and resizes the image over time using a timer control. 2. Checking if a number is even or odd, calculating factorials, and determining if a number is prime. 3. Calculating book discounts based on number of books purchased. 4. Creating forms to display student names in list boxes and allow shifting between lists, as well as displaying state capitals and cities based on combo box selection. 5. Creating arrays, finding frequencies of elements, and displaying positions. Also counting characters and words in a text

Uploaded by

Khushi Aglawe
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 26

1.

A] Make an application in Visual Basic, which display a picture when,

i) Command button with caption “click here” is clicked.

INPUT

Private Sub Command1_Click()


[Link] = 100
End Sub

Private Sub Timer1_Timer()


[Link] = LoadPicture("C:\Users\Public\Pictures\Sample Pictures\[Link]")
End Sub

OUTPUT
ii) After delay time 100ms(by using Timer control)

INPUT

Private Sub Command1_Click()


[Link] = 100
[Link]=LoadPictures(“C:\Users\Public\Pictures\Sample Pictures\[Link]")
End Sub

Private Sub Timer1_Timer()


[Link] = [Link] + 150
[Link] = [Link] + 120
If([Link] >=5500) then
[Link] = 0
End If
End Sub

OUTPUT
1] B)
V. Find a even/Odd number.

INPUT

Option Explicit
Dim no As Integer

Private Sub Command1_Click()


no = [Link]
If no Mod 2 = 0 Then
[Link] = "Given number is Even"
Else
[Link] = "Given number is Odd"
End If
End Sub

OUTPUT
VI. Find Factorial of number.

INPUT

Option Explicit
Dim a As Integer
Dim b As Integer
Dim i As Integer

Private Sub Command1_Click()


a = Val([Link])
b=1
For i = 1 To a
b=b*i
Next
[Link] = b
End Sub
OUTPUT
vii. Find if the number is Prime or Not Prime.

INPUT

Option Explicit
Dim check As Integer
Dim num As Integer
Dim i As Integer

Private Sub Command1_Click()


check = 1
num = [Link]
For i = 2 To (num - 1)
If num Mod i = 0 Then
check = 0
Exit For
End If
Next
If check = 0 Then
MsgBox"not prime"
Else
MsgBox"prime"
End If
End Sub
OUTPUT
2]A) A book stall gives discount on the books as per following condition,

No. of books purchased Discount


<=5 Nil
>5 and <=10 10%
>10 and <=1512%
>15 20%

Create a for, as follows to calculate the discount.

INPUT

Option Explicit
Dim n As Integer
Dim dis As Single
Dim tp As Single

Private Sub Command1_Click()


If [Link] = "" Or [Link] = "" Then
MsgBox "you must entered the price and no. of books", vbExclamation, "alert"
Else
[Link] = Val([Link]) * Val([Link])
End If
End Sub

Private Sub Command2_Click()


n = Val([Link])
tp = Val([Link])
If n < 5 Then
dis = 0
ElseIf n > 5 And n <= 10 Then
dis = tp * 10 / 100
ElseIf n > 10 And n <= 15 Then
dis = tp * 12 / 100
ElseIf n > 15 Then
dis = tp * 20 / 100
End If
[Link] = dis
[Link] = True
End Sub

Private Sub Command3_Click()


[Link] = Val([Link]) - Val([Link])
End Sub

OUTPUT
B] Design a form for speed control program using scrollbars.

INPUT
Private Sub Command1_Click()
[Link] = True
[Link] = 1
End Sub

Private Sub HScroll1_Change()


If Hscroll1 > 80 Then
MsgBox "Speed cannot be increased further", vbCritical, "ERROR"
[Link] = False
Else
[Link] = [Link]
End If
End Sub
OUTPUT
3]A] Design an application, which display a text and given choice to change text to bold, italic,
underline(any one or in combination) using checkbox controls.

INPUT

Private Sub Check1_Click()


If [Link] = 1 Then
[Link] = True
Else
[Link] = False
End If
End Sub

Private Sub Check2_Click()


If [Link] = 1 Then
[Link] = True
Else
[Link] = False
End If
End Sub

Private Sub Check3_Click()


If [Link] = 1 Then
[Link] = True
Else
[Link] = False
End If
End Sub
OUTPUT
B] Write a VB code to give five choices of colors. Design an application to choose any one color
using option button and change the forecolor of textbox caption.

INPUT
Private Sub Option1_Click()
If [Link] = True Then
[Link] = vbRed
Else
[Link] = vbBlack
End If
End Sub
Private Sub Option2_Click()
If [Link] = True Then
[Link] = vbBlue
Else
[Link] = vbBlack
End If
End Sub
Private Sub Option3_Click()
If [Link] = True Then
[Link] = vbMagenta
Else
[Link] = vbBlack
End If
End Sub
Private Sub Option4_Click()
If [Link] = True Then
[Link] = vbYellow
Else
[Link] = vbBlack
End If
End Sub
Private Sub Option5_Click()
If [Link] = True Then
[Link] = vbGreen
Else
[Link] = vbBlack
End If
End Sub
OUTPUT
4]A] Write a program in VB to build application to display sorted list of group A & group B
student in two list boxes. Make provision to shift name(s) on either side using ListBox control.
INPUT
Option Explicit
Dim i As Integer

Private Sub Command1_Click()


For i = 0 To [Link]
[Link] [Link](i)
Next
[Link]
End Sub

Private Sub Command2_Click()


If [Link] = 0 Then
MsgBox "list is empty ..."
ElseIf [Link] = -1 Then
MsgBox "You must select item ..."
Else
[Link] [Link]
[Link] [Link]
End If
End Sub

Private Sub Command3_Click()


If [Link] = 0 Then
MsgBox "list is empty ..."
ElseIf [Link] = -1 Then
MsgBox "You must select item ..."
Else
[Link] [Link]
[Link] [Link]
End If
End Sub

Private Sub Command4_Click()


For i = 0 To [Link]
[Link] [Link](i)
Next
[Link]
End Sub
OUTPUT
B] Write a program in VB to build application which display list of states. Make provision to
display Capital of the State and Cities when a particular State is selected using combo Box.
INPUT
Private Sub Command1_Click()
If [Link] = 0 Then
[Link] = ""
[Link] = "Mumbai"
ElseIf [Link] = 1 Then
[Link] = ""
[Link] = "Bhopal"
ElseIf [Link] = 2 Then
[Link] = ""
[Link] = "Gandhinagar"
ElseIf [Link] = 3 Then
[Link] = ""
[Link] = "Jiapur"
ElseIf [Link] = 4 Then
[Link] = ""
[Link] = "Hyderabad"
End If

If [Link] = 0 Then
[Link] = ""
[Link] = "Maharashtra"
ElseIf [Link] = 1 Then
[Link] = ""
[Link] = "Madhya Pradesh"
ElseIf [Link] = 2 Then
[Link] = ""
[Link] = "Gujrat"
ElseIf [Link] = 3 Then
[Link] = ""
[Link] = "Rajasthan"
ElseIf [Link] = 4 Then
[Link] = ""
[Link] = "Andhra Pradesh"
End If
End Sub

Private Sub Form_Load()


[Link] "Maharashtra"
[Link] "Madhya Pradesh"
[Link] "Gujrat"
[Link] "Rajasthan"
[Link] "Andhra Pradesh"

[Link] "Nagpur"
[Link] "Bhopal"
[Link] "Ahmedabad"
[Link] "Jaipur"
[Link] "Hyderabad"
End Sub
OUTPUT
5]A] Write a VB Program to create an array of N elements. Find the frequency of element and
display the positions in an array.

INPUT
Option Explicit
Dim a(5) As Integer
Dim i As Integer
Dim n As Integer
Dim cnt As Integer

Private Sub Command1_Click()


If i> 5 Then
MsgBox "overflow"
Else
a(i) = [Link]
i=i+1
[Link] = ""
[Link]
End If
End Sub

Private Sub Command2_Click()


n = Val([Link])
For i = 0 To 5
If n = a(i) Then
cnt = cnt + 1
End If
Next
[Link] = cnt
End Sub

Private Sub Command3_Click()


[Link] = ""
[Link] = ""
[Link] = ""
End Sub
OUTPUT
B] Create an application, which counts no. of characters and no. of words entered in TextBox.
INPUT

Private Sub Command1_Click()


Dim countchar, countword As Integer
Dim duptext As String
countchar = Len([Link])
duptext = Replace(Trim([Link]), vbNewLine, "")
If duptext = "" Then
countword = 0
Else
countword = 1

For i = 1 To Len(duptext)
If Mid(duptext, i, 1) = "" Then
If Mid(duptext, i - 1, 1) <> "" Then
countword = countword + 1
End If
End If
Next
End If
MsgBox "Number of characters:" &countchar&vbNewLine& "Number of words:" &countword
End Sub

OUTPUT
6] Create Menus using editor as follows.

And Write appropriate code on click event of New & Edit Menu Options.
INPUT
Private Sub menuexit_Click()
Unload Me
End Sub

Private Sub menunew_Click()


[Link] = True
End Sub

Private Sub menuopen_Click()


[Link]
End Sub

OUTPUT
7] Create a database [Link] using Visual Database Manager with fields code number pay(n),
Name of Emplyoee(T), Designation(T), Address(T), Joining date(T), Basics pay(n), Status(T)
[Permanent / Temporary], Department(T), [purchase, sales, account]. Achieve connectivity
using Data control. Develop an application in V.B to display the data of employee using
MSFlexgrid control as shown below with company’s logo.

OUTPUT
8] Design a Menu as shown below.
Create table [Link] using Visual Data Manager and connect it to V.B application using Data
Control. Display/view records using DbGridControl.
Create an application in V.B to open database of employee [Link] by using menu option
“OPEN”. Use APPEND and SAVE options to ADD & SAVE records in Database.

INPUT
Private Sub menuappend_Click()
[Link]
[Link]
End Sub

Private Sub menuexit_Click()


Unload Me
End Sub

Private Sub menuopen_Click()


[Link]
End Sub

Private Sub menusave_Click()


[Link]
[Link]
End Sub
OUTPUT
9] Open DataBase [Link] with fields:-
Name, Class, fees using Visual Data Manager use Data control for connectivity.
Develop a menu driven application in V.B. to:-
1) Compute total fees class wise.
2) Search a record of a particular student belonging to a particular class.

INPUT
Private Sub menuexit_Click()
Unload Me
End Sub

Private Sub menuopen_Click()


[Link]
End Sub

Private Sub menusearch_Click()


Dim s_name As String
s_name = InputBox("Enter the name of student to search")
[Link] "Name" & s_name & ""
If [Link] = True Then
MsgBox "Record not Found", vbInformation, "Result"
End If
End Sub

Private Sub menutotalfees_Click()


[Link]
Do While Not [Link]
Class = [Link](1).Value
If StrComp(Class, "BSC-1") = 0 Then
sum1 = Val(sum1 + [Link](2).Value)
ElseIf StrComp(Class, "BSC-2") = 0 Then
sum2 = Val(sum2 + [Link](2).Value)
ElseIf StrComp(Class, "BSC-3") = 0 Then
sum3 = Val(sum3 + [Link](2).Value)
End If
[Link]
Loop
MsgBox "Total Fees of BSC-1=" & sum1, vbInformation, "Result"
MsgBox "Total Fees of BSC-2=" & sum2, vbInformation, "Result"
MsgBox "Total Fees of BSC-3=" & sum3, vbInformation, "Result"
End Sub

Private Sub menucompute_Click()


sum1 = 0
sum2 = 0
sum3 = 0

[Link]
Do While Not [Link]
Class = [Link](1).Value
If StrComp(Class, "BSC-1") = 0 Then
sum1 = Val(sum1 + [Link](2).Value)
ElseIf StrComp(Class, "BSC-2") = 0 Then
sum2 = Val(sum2 + [Link](2).Value)
ElseIf StrComp(Class, "BSC-3") = 0 Then
sum3 = Val(sum3 + [Link](2).Value)
End If

[Link]
Loop
MsgBox "Total Fees of BSC-1=" & sum1, vbInformation, "Result"
MsgBox "Total Fees of BSC-2=" & sum2, vbInformation, "Result"
MsgBox "Total Fees of BSC-3=" & sum3, vbInformation, "Result"
End Sub

Private Sub menuexit_Click()


Unload Me
End Sub
OUTPUT
10] Create a DataBase [Link] containing fields:-
Name, Class, Marks in Phy, Comp. Sc., Math’s and percentage using Visual Data Manager.
Connect database to vb application using Data Control.
Develop a Menu driven application in V.B. to
1) Edit a records class wise.
2) Calculate class wise passing percentage where a student is declared “pass”, if he/she
gets percentage >= 45.
Display Class wise list of students who are placed in 1 st Division.(Percentage >=80)

INPUT
Private Sub Command1_Click()
[Link]
End Sub

Private Sub Command10_Click()


[Link] "class=' & [Link] & '"
If [Link] Then
MsgBox "Not Found"
End If
End Sub

Private Sub Command11_Click()


[Link] "class=' & [Link] & '"
If [Link] Then
MsgBox "Not Found"
End If
End Sub

Private Sub Command12_Click()


[Link] "class=' & [Link]& '"
If [Link] Then
MsgBox "Not Found"
End If
End Sub

Private Sub Command2_Click()


[Link](0) = [Link]
[Link](1) = [Link]
[Link](2) = [Link]
[Link](3) = [Link]
[Link](4) = [Link]
[Link](5) = [Link]
MsgBox "Record saved"
[Link]
MsgBox "Successfully saved", vbInformation, "Information"
[Link] = True
[Link] = True
[Link] = True
[Link] = True
[Link] = True
End Sub

Private Sub Command3_Click()


[Link]
End Sub
Private Sub Command4_Click()
Dim a As Integer
[Link] = ((Val([Link]) + Val([Link]) + Val([Link])) / 300) * 100
If Val([Link]) >= 90 And Val([Link]) <= 100 Then
MsgBox "Grade A"
ElseIf Val([Link]) >= 80 And Val([Link]) <= 90 Then
MsgBox "Grade B"
ElseIf Val([Link]) >= 70 And Val([Link]) <= 80 Then
MsgBox "Grade C"
Else
MsgBox "Grade D"
End If
End Sub

Private Sub Command5_Click()


[Link]
End Sub

Private Sub Command7_Click()


If [Link] Then
MsgBox "End of file", vbInformation, "ERROR"
Else
[Link]
End If
End Sub

Private Sub Command8_Click()


If [Link] Then
MsgBox "Begining of file", vbInformation, "ERROR"
Else
[Link]
End If
End Sub

Private Sub Command9_Click()


[Link] "Class=' & [Link]& '"
If [Link] Then
MsgBox "NotFound"
End If
End Sub

Private Sub menubsc1_Click()


[Link]
[Link] "class=BSC-1"
If [Link] Then
MsgBox "Not Found"
End If
End Sub

Private Sub menubsc2_Click()


[Link]
[Link] "class='BSC-2'"
If [Link] Then
MsgBox "Not Found"
End If
End Sub
Private Sub menubsc3_Click()
[Link] "class='BSC-3'"
If [Link] Then
MsgBox "Not Found"
End If
End Sub

Private Sub menucreate_Click()


[Link] = True
[Link] = True
[Link] = True
[Link] = True
[Link] = True
[Link] = True
End Sub

Private Sub menudisplay_Click()


[Link]
End Sub
OUTPUT
11] Create a table [Link] using VDM containing fields:-
Name of Books, subject, price, date of purchase, Name of publication.
Develop a menu driven application in V.B. to:-
1) Open Database.
2) Delete a record of book.
3) Display subject wise list of book in proper format.

INPUT
Private Sub menudelete_Click()
[Link]
End Sub

Private Sub menuexit_Click()


Unload Me
End Sub

Private Sub menuopen_Click()


[Link] = True
End Sub

Private Sub Combo1_Change()


[Link]
Call fillCombo
End Sub

Private Sub Command1_Click()


If MsgBox(" Are you sure you want to delete?", vbQuestion + vbYesNo, "Confirm") = vbYes Then
[Link]
MsgBox "Successfully Deleted", vbInformation, "Result"
End If
End Sub

Public Sub fillCombo()


[Link]
[Link]
Do While Not [Link]
[Link] [Link](0).Value
[Link]
Loop
End Sub
OUTPUT
12] Create a table using VDM to store required information for computing Electricity Bill.
Charges are as follows.
1) 1.25/units for 1st 30 units.
2) 2.90/units from 31 to 300 units.
3) 4.0/units from 301 to onwards.
Develop a menu driven application to:-
1) Open Database
2) Display Electricity Bill in proper format.
3) Delete a record of book.
4) Append a record.
5) Edit record.
INPUT
Private Sub Form_Load()
[Link] = False
End Sub

Private Sub menuappend_Click()


[Link]
End Sub

Private Sub menudelete_Click()


[Link]
End Sub

Private Sub menudisplay_Click()


n = Val([Link])
If n > 1 And n < 30 Then
[Link](2) = 1.25 * n
[Link]
ElseIf n > 31 And n > 300 Then
[Link](2) = 2.9 * n
[Link]
Else
[Link](2) = 4 * n
[Link]
End If
End Sub

Private Sub menuedit_Click()


[Link] = True
End Sub

Private Sub menuexit_Click()


Unload Me
End Sub

Private Sub menuopen_Click()


[Link] = True
End Sub
OUTPUT

You might also like