SYBCA-4 4 December 30, 1899
PROGRA Display personal information in msgbox.
M 11
Design
Code Public Class Form1
Private Sub Button1_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim info As String
info = "Roll No : " & [Link] & vbCrLf & "Name : " & [Link] & vbCrLf & "DOB :
" & [Link] & vbCrLf & "STATE : " & [Link] & vbCrLf & "City: " & [Link] &
vbCrLf & "PINCODE : " & [Link]
If [Link] Then
info = info & "Gender : " & [Link] & vbCrLf
ElseIf [Link] Then
info = info & "Gender : " & [Link] & vbCrLf
End If
If [Link] Then
info = info & "Hobby : " & [Link] & vbCrLf
End If
12
SYBCA-4 4 December 30, 1899
If [Link] Then
info = info & "Hobby : " & [Link] & vbCrLf
End If
If [Link] Then
info = info & "Hobby : " & [Link] & vbCrLf
End If
info = info & "Address : " & [Link] & vbCrLf & "CITY : " & [Link] & vbCrLf &
"STATE : " & [Link] & vbCrLf & "PINCODE : " & [Link]
Dim result As DialogResult
result = [Link](info, "Information Entered", [Link],
[Link])
If result = [Link] Then
[Link]("Submitted Successfully", "Success", [Link],
[Link])
ElseIf result = [Link] Then
[Link]("Check Properly", "Error", [Link],
[Link])
End If
End Sub
Private Sub BtnClose_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
[Link]()
End Sub
End Class
13
SYBCA-4 4 December 30, 1899
Output
14
SYBCA-4 4 December 30, 1899
PROGRA Count number of textboxes on form.
M 12
Design
Code Public Class Form1
Private Sub btnans_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim ctl As New Control
Dim ct As Integer
For Each ctl In [Link]
If TypeOf ctl Is TextBox Then
ct += 1
End If
Next
MsgBox(ct)
End Sub
End Class
Output
15
SYBCA-4 4 December 30, 1899
PROGRA Accept the name from InputBox and display name in thee messagebox.
M 13
Design
Code Public Class Form1
Private Sub btnans_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim nm As String = [Link]
MsgBox(nm)
End Sub
End Class
Output
16
SYBCA-4 4 December 30, 1899
PROGRA Create a sub procedure called hi() and when user click on button call it.
M 14
Design
Code Public Class Form1
Private Sub btnans_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Call hii()
End Sub
Private Sub hii()
MsgBox("hello armaan…¢Â€Â¦")
End Sub
End Class
Output
17
SYBCA-4 4 December 30, 1899
PROGRA Create square function which takes one argument and returns square of that argument
M 15 and call it on the click event of button.
Design
Code Public Class Form1
Private Sub btnans_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = square([Link])
End Sub
Function square(ByVal number As Integer)
Dim sq As Integer = number * number
Return sq
End Function
End Class
Output
18
SYBCA-4 4 December 30, 1899
PROGRA Create a function to check whether a given number is odd or even and call it on
M 16 the click event of button.
Design
Code Public Class Form1
Private Sub btnsub_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
If IsEven([Link]) Then
[Link] = "Number is Even"
Else
[Link] = "Number is Odd"
End If
End Sub
Function IsEven(ByVal a As Integer) As Boolean
If a Mod 2 = 0 Then
Return True
Else
Return False
End If
End Function
End Class
19
SYBCA-4 4 December 30, 1899
Output
20
SYBCA-4 4 December 30, 1899
PROGRA Create multiplication function which has 3 arguments and 1 of them is optional
M 17 argument and call it on the click event of button.
Design
Code Public Class Form1
Function Mul(ByVal K As Integer, ByVal R As Integer, Optional ByVal N As Integer = 7) As
Integer
Return K * R * N
End Function
Private Sub BtnAns_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim Ans As Integer
Ans = Mul(19, 9)
MsgBox(Ans)
End Sub
End Class
21
SYBCA-4 4 December 30, 1899
Output
22
SYBCA-4 4 December 30, 1899
PROGRA Create 4 add() functions that show the demo of function overloading and call it
M 18 on the click event of button.
Design
Code Public Class Form1
Function Add()
Return 0
End Function
Function Add(ByVal A As Integer) As Integer
Return A + 0
End Function
Function Add(ByVal A As Integer, ByVal B As Integer) As Integer
Return A + B + 0
End Function
Function Add(ByVal A As Integer, ByVal B As Integer, ByVal C As Integer) As Integer
Return A + B + C + 0
End Function
Private Sub Btnadd_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim Ans As Integer
Ans = Add(1)
[Link] = Ans
Ans = Add(25)
[Link] = Ans
Ans = Add(20, 10)
23
SYBCA-4 4 December 30, 1899
[Link] = Ans
Ans = Add(29, 11, 19)
[Link] = Ans
End Sub
End Class
Output
24
SYBCA-4 4 December 30, 1899
PROGRA Create a functions that show the swapping of 2 values on the click event of
M 19 button.
Design
Code Public Class Form1
Private Sub btnswap_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim A, B As Integer
A = [Link]
B = [Link]
Swap(A, B)
[Link] = A
[Link] = B
End Sub
Sub Swap(ByRef x As Integer, ByRef y As Integer)
Dim temp As Integer
temp = x
x=y
y = temp
End Sub
End Class
25
SYBCA-4 4 December 30, 1899
Output
26
SYBCA-4 4 December 30, 1899
PROGRA Count the number of even and odd in a given string.
M 20
Design
Code Public Class EvenODD
Private Sub Button1_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
Dim no As Integer = [Link]()
Dim i, even, odd As Integer
For i = 1 To no
If i Mod 2 = 0 Then
even += 1
Else
odd += 1
End If
Next
[Link] = even
[Link] = odd
End Sub
End Class
27
SYBCA-4 4 December 30, 1899
Output
28
SYBCA-4 4 December 30, 1899
PROGRA Fetch data from database and display in DataGridView.
M 21
Design
Code Imports [Link]
Imports [Link]
Public Class Form1
Private Sub Form1_Load(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim con As New
OleDbConnection("Provider=[Link].12.0;Data Source=C:\
Users\ADNAN-ARMAN-2022\Documents\Visual Studio 2010\Projects\
[Link]")
Dim cmd As New OleDbCommand("SELECT * FROM STUDENT", con)
Dim da As New OleDbDataAdapter(cmd)
Dim ds As New [Link]
[Link](ds)
[Link] = [Link](0)
[Link]()
End Sub
End Class
Output
29
SYBCA-4 4 December 30, 1899
30
SYBCA-4 4 December 30, 1899
PROGRA Write a code to fill combobox from the database.
M 22
Design
Code Imports [Link]
Public Class Form1
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles
[Link]
' Connection string to your Access database
Dim connectionString As String = "Provider=[Link].12.0;Data
Source=C:\Users\Admin\Documents\Visual Studio 2010\Projects\[Link]"
' SQL query to select data from the database
Dim query As String = "SELECT Name FROM Emp"
' Create a new OleDbConnection object with the connection string
Using connection As New OleDbConnection(connectionString)
' Create a new OleDbCommand object with the query and the connection
Using command As New OleDbCommand(query, connection)
Try
' Open the connection
[Link]()
' Create a OleDbDataReader to read data
Dim reader As OleDbDataReader = [Link]()
' Clear existing items in the ComboBox
[Link]()
' Read each row from the OleDbDataReader
While [Link]()
' Add the value from the "ColumnName" column to the ComboBox
31
SYBCA-4 4 December 30, 1899
[Link](reader("Name").ToString())
End While
' Close the OleDbDataReader
[Link]()
Catch ex As Exception
' Handle any errors that occur
[Link]("Error: " & [Link])
End Try
End Using
End Using
End Sub
End Class
Output
32
SYBCA-4 4 December 30, 1899
PROGRA Establish database connection with databinding context and provide
M 23 Add,Update, Delete and Cancel functionality.
Design
33
SYBCA-4 4 December 30, 1899
Code Imports [Link]
Imports [Link]
Public Class Form1
Dim con As New OleDbConnection("Provider=[Link].12.0;Data
Source=C:\Users\Admin\Documents\Visual Studio 2010\Projects\[Link]")
Dim cmd As OleDbCommand
Private Sub Button1_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
cmd = New OleDbCommand("insert into Emp values('" & [Link] & "','" &
[Link] & "','" & [Link] & "','" & [Link] & "')", con)
[Link]()
[Link]()
MsgBox("Record Inserted")
[Link]()
End Sub
Private Sub Button2_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
cmd = New OleDbCommand("UPDATE Emp SET Sname='" & [Link] &
"',Dept='" & [Link] & "' where ID=" & [Link], con)
[Link]()
[Link]()
MsgBox("Record updated")
[Link]()
End Sub
Private Sub Button3_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
cmd = New OleDbCommand("DELETE FROM Emp WHERE Dept='"& [Link]
&"'", con)
[Link]()
[Link]()
MsgBox("Recorde Deleted")
[Link]()
End Sub
End Class
34
SYBCA-4 4 December 30, 1899
Output
35
SYBCA-4 4 December 30, 1899
36
SYBCA-4 4 December 30, 1899
PROGRA Provide Add, Update, Delete, Cancel and navigation functionality on the
M 24 database using ExecuteReader.
Design
Code Imports
[Link]
Imports [Link]
Public Class Form1
Dim con As
OleDbConnection Dim
cmd As OleDbCommand
Dim da As
OleDbDataAdapter Dim
ds As DataSet
Shared curPos As
Integer Dim flag As
Boolean = False
Dim boldatachange As Boolean = False
Private Sub Form1_Load(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
con = New OleDbConnection("Provider=[Link].12.0;Data Source=C:\
Users\Admin\Documents\Visual Studio 2010\Projects\[Link]")
cmd = New OleDbCommand("select * from Student order by ID",
con) da = New OleDbDataAdapter(cmd)
ds = New
DataSet
[Link](ds)
curPos = 0
Show_Rec(cur
Pos) End Sub
37
SYBCA-4 4 December 30, 1899
Private Sub Button1_Click(ByVal sender As [Link], ByVal e As
[Link])
Handles
[Link]
curPos = 0
Show_Rec(curPos)
End Sub
Private Sub Button2_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
If curPos > 0
Then
curPos -= 1
End If
Show_Rec(cur
Pos) End Sub
Private Sub Button3_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
If curPos < [Link](0).[Link] - 1
Then curPos += 1
End If
Show_Rec(cur
Pos) End Sub
Private Sub Button4_Click(ByVal sender As [Link], ByVal e As
[Link])
Handles [Link]
curPos =
[Link](0).[Link] - 1
Show_Rec(curPos)
End
Sub
Private Sub Button5_Click(ByVal sender As [Link], ByVal e As
[Link])
Handles
[Link]
flag = True
clear_All()
[Link] =
GetNext() End Sub
Private Sub Button6_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim tmpcmd As New
38
SYBCA-4 4 December 30, 1899
OleDbCommand Dim strqry As
String
[Link] =
con If flag = True Then
strqry = "INSERT INTO Student VALUES('" & [Link] & "','" & [Link] &
"')"
Else
strqry = "UPDATE Student SET Name='" & [Link] & "' WHERE ID=" &
[Link]
End If
MsgBox(strqry)
[Link]= strqry
[Link]
ry() boldatachange =
True
flag = False
If [Link] = 1
Then
[Link]()
E
nd If
End
Sub
Private Sub Button7_Click(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
Dim tmpcmd As New
OleDbCommand If [Link] = 0
Then
[Link]()
End If
[Link] = con
[Link] = "delete from Student where ID=" & [Link]
[Link]()
curPos = 0
boldatachange =
True
Show_Rec(curPos
)
If [Link] = 0
Then
[Link]()
39
SYBCA-4 4 December 30, 1899
E
nd If
End
Sub
Private Sub Button8_Click(ByVal sender As [Link], ByVal e As
[Link])
Handles
[Link]
flag = False
Show_Rec(cur
Pos) End Sub
Sub clear_All()
[Link]
= ""
[Link]
r()
End
Sub
Function GetNext() As Integer
Dim tmpcmd As
OleDbCommand If [Link]
= 0 Then
[Link]()
End If
[Link] = con
[Link] = "SELECT max(ID) FROM Student"
Return [Link]() + 1
If [Link] = 1
Then
[Link]()
End If
End Function
Sub Show_Rec(ByVal pos As Integer)
If boldatachange
Then ds = New
DataSet [Link](ds)
boldatachange =
False
End If
[Link] = [Link](0).Rows(pos)("ID")
[Link] = [Link](0).Rows(pos)("Name")
End Sub
End Class
40
SYBCA-4 4 December 30, 1899
Output
41
SYBCA-4 4 December 30, 1899
42
SYBCA-4 4 December 30, 1899
43
SYBCA-4 4 December 30, 1899
44
SYBCA-4 4 December 30, 1899
PROGRA Create database containing Emp table. Columns of Emp table are Empno, Ename,
M 25 Salary. Write down coding for database connectivity with Binding manager and 8
buttons with proper controls.
Design
Code Imports [Link]
Imports [Link]
Public Class Form1
Dim bm As BindingManagerBase
Dim ds As New [Link]
Private Sub Form1_Load(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
Dim con As New OleDbConnection("Provider=[Link].12.0;Data
Source=C:\Users\Admin\Documents\Visual Studio 2010\Projects\[Link]")
Dim cmd As New OleDbCommand("select Empno,Ename from Emp", con)
Dim da As New OleDbDataAdapter(cmd)
[Link](ds)
bm = [Link]([Link](0))
[Link]("Text", [Link](0), "Empno")
[Link]("Text", [Link](0), "Ename")
End Sub
Private Sub Button1_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = 0
End Sub
Private Sub Button2_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = [Link] - 1
End Sub
45
SYBCA-4 4 December 30, 1899
Private Sub Button3_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = [Link] + 1
End Sub
Private Sub Button4_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link] = [Link]
End Sub
Private Sub Button5_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link]()
End Sub
Private Sub Button6_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link]([Link])
End Sub
Private Sub Button7_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link]()
End Sub
Private Sub Button8_Click(ByVal sender As [Link], ByVal e As [Link])
Handles [Link]
[Link]()
End Sub
End Class
Output
46
SYBCA-4 4 December 30, 1899
47
SYBCA-4 4 December 30, 1899
48
SYBCA-4 4 December 30, 1899
PROGRA Create database containing Movie table. Columns of Movie table are
M 26 Mno,Mname, Hero, Heroine. Write down coding for database connectivity
and use different controls like combobox, textboxes, labels, radiobuttons,
checkboxes etc and 8 buttons for functionality.
Design
Code Imports [Link]
Public Class Form
Dim connectionString As String =
("Provider=[Link].12.0;Data Source=C:\Users\ARMAAN
SHAIKH\OneDrive\Documents\[Link]")
Dim connection As OleDbConnection
Dim command As OleDbCommand
Dim dataAdapter As OleDbDataAdapter
Dim dataSet As DataSet
Dim dataTable As DataTable
Dim rowIndex As Integer
Private Sub Form1_Load(ByVal sender As [Link], ByVal e As
[Link]) Handles [Link]
connection = New OleDbConnection(connectionString)
[Link]()
command = New OleDbCommand("SELECT * FROM MOBIES", connection)
dataAdapter = New OleDbDataAdapter(command)
dataSet = New DataSet()
[Link](dataSet, "MOBIES")
dataTable = [Link]("MOBIES")
rowIndex = 0
DisplayData()
End Sub
Private Sub DisplayData()
[Link] = [Link](rowIndex)("HERO").ToString()
[Link] = [Link](rowIndex)("HEROINE").ToString()
[Link] = [Link](rowIndex)("MNAME").ToString()
End Sub
Private Sub Button1_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
rowIndex = 0
DisplayData()
End Sub
49
SYBCA-4 4 December 30, 1899
Private Sub Button2_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
If rowIndex > 0 Then
rowIndex -= 1
DisplayData()
End If
End Sub
Private Sub Button3_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
If rowIndex < [Link] - 1 Then
rowIndex += 1
DisplayData()
End If
End Sub
Private Sub Button4_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
rowIndex = [Link] - 1
DisplayData()
End Sub
Private Sub Button5_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
Dim newMovieName As String = [Link]
Dim newMovieHero As String = [Link]
Dim newMovieHeroine As String = [Link]
Using connection As New OleDbConnection(connectionString)
Dim query As String = "INSERT INTO MOBIES(MNAME, HERO,
HEROINE) VALUES (@MNAME, @HERO, @HEROINE)"
Dim command As New OleDbCommand(query, connection)
[Link]("@MNAME", newMovieName)
[Link]("@HERO", newMovieHero)
[Link]("@HEROINE",
newMovieHeroine)
[Link]()
[Link]()
[Link]("New movie added successfully.")
End Using
End Sub
Private Sub Button6_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
Dim selectedMovie As String = [Link]
Dim updatedHero As String = [Link]
Dim updatedHeroine As String = [Link]
Using connection As New OleDbConnection(connectionString)
Dim query As String = "UPDATE MOBIES SET HERO = @HERO,
HEROINE = @HEROINE WHERE MNAME = @MNAME"
Dim command As New OleDbCommand(query, connection)
[Link]("@HERO", updatedHero)
[Link]("@HEROINE",
50
SYBCA-4 4 December 30, 1899
updatedHeroine)
[Link]("@MNAME", selectedMovie)
[Link]()
[Link]()
[Link]("Movie updated successfully.")
End Using
End Sub
Private Sub Button7_Click(ByVal sender As [Link], ByVal e
As [Link]) Handles [Link]
Dim selectedMovie As String = [Link]
Using connection As New OleDbConnection(connectionString)
Dim query As String = "DELETE FROM MOBIES WHERE MNAME =
@MNAME"
Dim command As New OleDbCommand(query, connection)
[Link]("@MNAME", selectedMovie)
[Link]()
[Link]()
[Link]("Movie deleted successfully.")
End Using
End Sub
End Class
Output
51
SYBCA-4 4 December 30, 1899
52
SYBCA-4 4 December 30, 1899
53
SYBCA-4 4 December 30, 1899
54