GADPR
GADPR
Imports System.Data.OleDb
Public Class Form1
End Sub
End Class
2) Design a windows application that display multiple table on data grid view
Imports System.Data.OleDb
Public Class Form1
DataGridView1.DataSource = ds.Tables("Student")
DataGridView2.DataSource = ds.Tables("Details")
End Sub
End Class
3) Imports System.Data.OleDb
Public Class Form1
Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\HARSHAD
THOK\OneDrive\Documents\Database5.accdb")
End Sub
4)Navigation
Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer
da.Fill(ds)
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.Text = ds.Tables(0).Rows(0).Item(1)
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(0).Rows(0).Item(3)
max = ds.Tables(0).Rows.Count
max = max - 1
End Sub
Public Sub nav(ByVal r As Integer)
TextBox1.Text = ds.Tables(0).Rows(r).Item(0)
TextBox2.Text = ds.Tables(0).Rows(r).Item(1)
TextBox3.Text = ds.Tables(0).Rows(r).Item(2)
TextBox4.Text = ds.Tables(0).Rows(r).Item(3)
End Sub
nav(min)
End Sub
End Sub
5)
complex binding
Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer
End Sub
End Class
6)simple binding
Imports System.Data.OleDb
Public Class Form1
Dim min As Integer = 0
Dim max As Integer
da.Fill(ds, "Student")
TextBox1.Text = ds.Tables(0).Rows(0).Item(0)
TextBox2.DataBindings.Add("Text", ds, "Student.Name1")
TextBox3.Text = ds.Tables(0).Rows(0).Item(2)
TextBox4.Text = ds.Tables(0).Rows(0).Item(3)
End Sub
End Class
7)Exception Handaling
Module Module1
Sub Main()
Dim Rollno, age As Integer
Dim Name As String
Try
Console.WriteLine("Enter Rollno and name:")
Rollno = Console.ReadLine()
Name = Console.ReadLine()
Console.WriteLine("Enter Age ")
age = Console.ReadLine()
If age <= 0 Then
Throw New Exception("Entered age is negative")
Else
Console.WriteLine("Regestaration Successful")
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Console.ReadKey()
End Sub
End Module
Output:
8)through inheritance
Module Module1
Sub Main()
Dim d As New derived
d.proc()
Console.ReadKey()
End Sub
End Module
Class base
Sub proc()
Console.WriteLine("Base class Method")
End Sub
End Class
Class derived
Inherits base
Shadows Sub proc()
Console.WriteLine("Derived Class Method")
MyBase.proc()
End Sub
End Class
Output:
Derived Class Method
Base class Method
9)through Scope
Module Module1
Sub Main()
Dim z As New class1
z.p()
Console.ReadKey()
End Sub
End Module
Class class1
Public temp As Integer = 5
Sub p()
Dim temp As Integer = 10
Dim y As Integer = temp
Dim z As Integer = MyClass.temp
Console.WriteLine("Y=" & y)
Console.WriteLine("Z=" & z)
End Sub
End Class
Output:
Y=10
Z=5
10)overload
Public Class Form1
Dim s1, s2 As String
Public Overloads Sub concat(ByVal str1 As String, ByVal str2 As String)
s1 = str1
s2 = str2
End Sub
Public Overloads Sub concat()
MessageBox.Show("Concated String is:" & (s1 + s2))
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
concat(TextBox1.Text, TextBox2.Text)
concat()
End Sub
End Class
Output:
11)inheritance
Module Module1
Sub Main()
Dim s As New Student
s.accept1()
s.accept2()
s.display()
Console.ReadKey()
End Sub
End Module
Public Class Faculty
Public n As String
Public a As Integer
Sub accept1()
Console.WriteLine("ENter Name and age")
n = Console.ReadLine()
a = Console.ReadLine()
End Sub
End Class
Class Student
Inherits Faculty
Dim n1, c As String
Public Sub accept2()
Console.WriteLine("ENter Name and class of student")
n1 = Console.ReadLine()
c = Console.ReadLine()
End Sub
Sub display()
Console.WriteLine("Name of Faculty:" & n)
Console.WriteLine("Age of FAculty=" & a)
Console.WriteLine("Name OF Student=" & n1)
Console.WriteLine("Class Of Student=" & c)
End Sub
End Class
Output:
12)constructor
Module Module1
Sub Main()
Dim radius As Integer
Console.WriteLine("Enter Radius:")
radius = Console.ReadLine()
Dim obj As New Area(radius)
Console.ReadKey()
End Sub
End Module
Class Area
Sub New(ByVal r As Integer)
Dim area As Double
area = 3.14 * r * r
Console.WriteLine("Area=" & area)
End Sub
End Class
Output:
Enter Radius:
5
Area=78.5
13)destructor
Module Module1
Sub Main()
Dim radius As Integer
Console.WriteLine("Enter Radius:")
radius = Console.ReadLine()
Dim obj As New Area()
obj.Area(radius)
Console.ReadKey()
End Sub
End Module
Class Area
Sub Area(ByVal r As Integer)
Dim area As Double
area = 3.14 * r * r
Console.WriteLine("Area=" & area)
End Sub
Protected Overrides Sub finalize()
Console.WriteLine("Destructor Call")
End Sub
End Class
Module Module1
Sub Main()
Dim b As New Box
b.volume(3, 4, 5)
Console.ReadKey()
End Sub
End Module
Class Box
Sub volume(ByVal l As Integer, ByVal b As Integer, ByVal h As Integer)
Dim v As Double
v = l * b * h
Console.WriteLine("Volume=" & v)
End Sub
End Class
Output:
Volume=60
15)
Module Module1
Dim i As Integer
Public Function fact(ByVal no As Integer)
i = no
If i = 1 Then
Return 1
Else
Return i * fact(i - 1)
End If
End Function
Sub main()
Dim f, n As Integer
Console.WriteLine("Enter the no:")
i = Console.ReadLine()
n = i
f = fact(i)
Console.WriteLine("Factorial of " & n & " is " & f)
Console.ReadKey()
End Sub
End Module
Output:
Enter the no:
5
Factorial of 5 is 120
16) procedure
Imports System.Math
Module Module1
Dim i, rev, digit As Integer
Public Sub reve(ByVal no As Integer)
While (no > 0)
digit = no Mod 10
rev = rev * 10 + digit
no = Math.Floor(no / 10)
End While
Console.WriteLine("Reverse of no is " & rev)
End Sub
Sub main()
Console.ReadKey()
End Sub
End Module
Output:
Enter the no:
567
Reverse of no is 765
17)
Validation
Imports System.Text.RegularExpressions
Public Class Form1
Dim rm As New Regex("^[A-Z][a-zA-z0-9_]{5,15}$")
Dim rv As New Regex("^[a-zA-z0-9_@]{8,15}$")
Dim fv As New Regex("^[0-9]{10}$")
Dim nv As New Regex("^[a-zA-Z0-9+_.]+@[a-zA-z0-9._]+[.][a-zA-Z]{2,3}$")
Private Sub TextBox1_Validating(sender As Object, e As
System.ComponentModel.CancelEventArgs) Handles TextBox1.Validating
If rm.IsMatch(TextBox1.Text) Then
ErrorProvider1.SetError(TextBox1, "")
Else
ErrorProvider1.SetError(TextBox1, "Please Enter valid Username ")
e.Cancel = True
End If
End Sub
End If
End Sub
End If
End Sub
End If
End Sub
End Class
18)Timer control
Public Class Form1
Dim cnt As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
cnt = cnt + 1
Label1.Text = TimeOfDay
If cnt >= 0 And cnt <= 120 Then
OvalShape1.Visible = True
OvalShape2.Visible = False
OvalShape3.Visible = False
ElseIf cnt > 120 And cnt <= 150 Then
OvalShape1.Visible = False
OvalShape2.Visible = True
OvalShape3.Visible = False
ElseIf cnt > 150 And cnt <= 220 Then
OvalShape1.Visible = False
OvalShape2.Visible = False
OvalShape3.Visible = True
Else
cnt = 0
End If
End Sub
End Class
19)picture box
Public Class Form1
End Sub
End Class