Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

1) Write a VB.

Net Program to display the numbers continuously in TextBox by clicking on


Button.
Public Class Form1
Dim counter As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
counter = 0
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick
counter = counter + 1
TextBox1.Text = counter
End Sub
End Class

2) Write a Vb.Net program to move the Text “Pune University” continuously from Left
to Right and Vice Versa.

Public Class MoveText


Private Sub MoveText_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Timer1.Enabled = True
End Sub

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Timer1.Tick
Label1.Left += 1
If Label1.Left >= 12000 Then
Timer1.Enabled = False
End If
End Sub
End Class

3) Write a program in C# .Net to create a function for the sum of two numbers.
using System;
namespace Add{
public class Program{
public static int addition(int a, int b){
return (a+b);
}
public static void Main(){
int a,b;
int sum;
Console.Write("Enter first number: ");
a = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter second number: ");
b = Convert.ToInt32(Console.ReadLine());
sum = addition(a,b);
Console.WriteLine("Sum is: " + sum);
}} }
4) Write a VB.NET program to accept a character from keyboard and check whether it
is vowel or consonant. Also display the case of that character.
Public Class VowelCheck

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


Handles btnvowel.Click
Dim c As Char
c = txtchar.Text
If Char.IsUpper(c) Then
MsgBox("Upper Case Character")
ElseIf Char.IsLower(c) Then
MsgBox("Lower Case Character")
End If
Select Case c
Case "A"
MsgBox("Vowel")
Case "B"
MsgBox("Vowel")
Case "C"
MsgBox("Vowel")
Case "D"
MsgBox("Vowel")
Case "E"
MsgBox("Vowel")
Case "a"
MsgBox("Vowel")
Case "b"
MsgBox("Vowel")
Case "c"
MsgBox("Vowel")
Case "d"
MsgBox("Vowel")
Case "e"
MsgBox("Vowel")
Case Else
MsgBox("Not Vowel")
End Select
End Sub
End Class

5) Design a VB.net form to pick a date from DateTimePicker Control and display day, month
and year in separate text boxes.
Public Class DateTimepker

Private Sub DateTimePicker1_ValueChanged(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles DateTimePicker1.ValueChanged
txtday.Text = DateTimePicker1.Value.Day
txtmonth.Text = DateTimePicker1.Value.Month
txtyear.Text = DateTimePicker1.Value.Year
End Sub
End Class
6) Write a c#.Net program for multiplication of matrices.
using System;
public class Exercise21
{
public static void Main()
{
int i,j,k,r1,c1,r2,c2,sum=0;

int[,] arr1 = new int[50,50];


int[,] brr1 = new int[50,50];
int[,] crr1 = new int[50,50];

Console.Write("\n\nMultiplication of two Matrices\n");


Console.Write("----------------------------------\n");

Console.Write("\nInput the number of rows and columns of the first matrix :\n");
Console.Write("Rows : ");
r1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Columns : ");
c1 = Convert.ToInt32(Console.ReadLine());

Console.Write("\nInput the number of rows of the second matrix :\n");


Console.Write("Rows : ");
r2 = Convert.ToInt32(Console.ReadLine());
Console.Write("Columns : ");
c2 = Convert.ToInt32(Console.ReadLine());

if(c1!=r2){
Console.Write("Mutiplication of Matrix is not possible.");
Console.Write("\nColumn of first matrix and row of second matrix must be same.");
}
else
{
Console.Write("Input elements in the first matrix :\n");
for(i=0;i<r1;i++)
{
for(j=0;j<c1;j++)
{
Console.Write("element - [{0}],[{1}] : ",i,j);
arr1[i,j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.Write("Input elements in the second matrix :\n");
for(i=0;i<r2;i++)
{
for(j=0;j<c2;j++)
{
Console.Write("element - [{0}],[{1}] : ",i,j);
brr1[i,j] = Convert.ToInt32(Console.ReadLine());
}
}
Console.Write("\nThe First matrix is :\n");
for(i=0;i<r1;i++)
{
Console.Write("\n");
for(j=0;j<c1;j++)
Console.Write("{0}\t",arr1[i,j]);
}

Console.Write("\nThe Second matrix is :\n");


for(i=0;i<r2;i++)
{
Console.Write("\n");
for(j=0;j<c2;j++)
Console.Write("{0}\t",brr1[i,j]);
}
//multiplication of matrix
for(i=0;i<r1;i++)
for(j=0;j<c2;j++)
crr1[i,j]=0;
for(i=0;i<r1;i++) //row of first matrix
{
for(j=0;j<c2;j++) //column of second matrix
{
sum=0;
for(k=0;k<c1;k++)
sum=sum+arr1[i,k]*brr1[k,j];
crr1[i,j]=sum;
}}
Console.Write("\nThe multiplication of two matrix is : \n");
for(i=0;i<r1;i++) {
Console.Write("\n");
for(j=0;j<c2;j++) {
Console.Write("{0}\t",crr1[i,j]);
}
} }
Console.Write("\n\n");
}}

7) Write a VB.net program for blinking an image.


Public Class Form1

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


Handles Button1.Click
Timer1.Enabled = True
End Sub

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


Handles Timer1.Tick
If PictureBox1.Visible = True Then
PictureBox1.Visible = False
End If
If PictureBox1.Visible = False Then
PictureBox1.Visible = True
End If
End Sub
End Class
8) Write a C# Program to accept and display ‘n’ student’s details such as Roll. No, Name, marks
in three subjects, using class. Display percentage of each student.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Exercise12


{
static void Main(string[] args)
{
double rl,phy,che,ca,total;
double per;
string nm,div;

Console.Write("\n\n");
Console.Write("Calculate the total, percentage and division to take marks of three
subjects:\n");
Console.Write("------------------------------------------------");
Console.Write("\n\n");

Console.Write("Input the Roll Number of the student :");


rl = Convert.ToInt32(Console.ReadLine());

Console.Write("Input the Name of the Student :");


nm = Console.ReadLine();

Console.Write("Input the marks of Physics : ");


phy= Convert.ToInt32(Console.ReadLine());
Console.Write("Input the marks of Chemistry : ");
che = Convert.ToInt32(Console.ReadLine());
Console.Write("Input the marks of Computer Application : ");
ca = Convert.ToInt32(Console.ReadLine());

total = phy+che+ca;
per = total/3.0;
if (per>=60)
div="First";
else
if (per<60&&per>=48)
div="Second";
else
if (per<48&&per>=36)
div="Pass";
else
div="Fail";

Console.Write("\nRoll No : {0}\nName of Student : {1}\n",rl,nm);


Console.Write("Marks in Physics : {0}\nMarks in Chemistry : {1}\nMarks in Computer
Application : {2}\n",phy,che,ca);
Console.Write("Total Marks = {0}\nPercentage = {1}\nDivision = {2}\n",total,per,div);
}}
9) Write a C#.Net application to display the vowels from a given String.
string vowels = "aeiou";
string str = textBox1.Text;
char[] ch = str.ToCharArray();
foreach (char c in ch)
{
if (vowels.Contains(c.ToString())) {
Response.Write("vowels :-" + c.ToString() + "<br/>"); }
else {
Response.Write("consonant :- " + c.ToString() + "<br/>"); //consonant
} }
10) Write a VB.NET program to accept the details of product (PID, PName, expiry_date, price).
Store it into the database and display it on data grid view.

Imports System.Data.OleDb
Imports System.Data
Public Class Form1

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


Handles MyBase.Load
DataSet21.Clear()
Me.OleDbDataAdapter1.Fill(DataSet21, "Prod")
End Sub

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


Handles btnfirst.Click
Me.BindingContext(DataSet21, "Prod").Position = 0
End Sub

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


Handles btnprev.Click
Me.BindingContext(DataSet21, "Prod").Position = Me.BindingContext(DataSet21,
"Prod").Position - 1
End Sub

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


Handles btnnext.Click
Me.BindingContext(DataSet21, "Prod").Position = Me.BindingContext(DataSet21,
"Prod").Position + 1
End Sub

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


Handles btnlast.Click
Me.BindingContext(DataSet21, "Prod").Position = Me.BindingContext(DataSet21,
"Prod").Count - 1
End Sub

11) Write a VB.NET program to accept a number from user through input box and display its
multiplication table into the list box.
Public Class MultiplTable
Dim n, i, ans As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
i=1
ans = 1
n = InputBox("Enter Number:")
While i <= 10
ans = n * i
ListBox1.Items.Add(ans)
i=i+1
End While
End Sub

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


Handles Button2.Click
ListBox1.Items.Clear()
End Sub
End Class

12) Write a VB.NET program to create player table (PID, PName, Game, no_of_matches). Insert
records and update number of matches of ‘Rohit Sharma’ and display result in data grid view.
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider = MICROSOFT.JET.OLEDB.4.0;data
Source=D:\sym\VB.NET\Player.mdb")
Dim cmd As New OleDbCommand
Dim ad As New OleDbDataAdapter
Dim ds As New DataSet

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


Handles Button1.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "insert into game values (" & TextBox1.Text & ",'" & TextBox2.Text
& "','" & TextBox3.Text & "', " & TextBox3.Text & ")"
cmd.ExecuteNonQuery()
MsgBox("Record inserted succesfully")
con.Close()
End Sub

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


Handles btnupdate.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "update game set game.matches=" & TextBox4.Text & " where
game.pname='Rohit Sharma' "
cmd.ExecuteNonQuery()
MsgBox("Record updated succesfully")
con.Close()
End Sub
13) Write a program in C# to create a function to swap the values of two integers.
using System;
public class funcexer6
{
public static void interchange(ref int num1, ref int num2)
{
int newnum;

newnum = num1;
num1 = num2;
num2 = newnum;
}
public static void Main()
{
int n1,n2;
Console.Write("\n\nFunction : To swap the values of two integer numbers :\n");
Console.Write("----------------------------------------------------------\n");
Console.Write("Enter a number: ");
n1= Convert.ToInt32(Console.ReadLine());
Console.Write("Enter another number: ");
n2= Convert.ToInt32(Console.ReadLine());
interchange( ref n1, ref n2 );
Console.WriteLine( "Now the 1st number is : {0} , and the 2nd number is : {1}", n1,
n2 );
}
}

14) Write a Vb.net program to design the following form; it contains the three menus Color
(Red, Blue, and Green), Window (Maximize, Minimize, and Restore) and Exit. On Selection of
any menu or submenu result should affect the form control( for example if user selected Red
color from Color menu back color of form should get changed to Red and if user selected
Maximize from Window Menu then form should get maximized).
Public Class menuprg

Private Sub RedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RedToolStripMenuItem.Click
Me.BackColor = Color.Red
End Sub

Private Sub GreenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GreenToolStripMenuItem.Click
Me.BackColor = Color.Green
End Sub
Private Sub BlueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles BlueToolStripMenuItem.Click
Me.BackColor = Color.Blue
End Sub

Private Sub NormalToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles NormalToolStripMenuItem.Click
Me.WindowState = FormWindowState.Normal
End Sub

Private Sub MinimisedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MinimisedToolStripMenuItem.Click
Me.WindowState = FormWindowState.Minimized
End Sub

Private Sub MaximisedToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MaximisedToolStripMenuItem.Click
Me.WindowState = FormWindowState.Maximized
End Sub

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub

Private Sub RedToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles RedToolStripMenuItem1.Click
Me.BackColor = Color.Red
End Sub

Private Sub GreenToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles GreenToolStripMenuItem1.Click
Me.BackColor = Color.Green
End Sub

Private Sub BlueToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles BlueToolStripMenuItem1.Click
Me.BackColor = Color.Blue
End Sub

Private Sub NormalToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles NormalToolStripMenuItem1.Click
Me.WindowState = FormWindowState.Normal
End Sub

Private Sub MinimumToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MinimumToolStripMenuItem.Click
Me.WindowState = FormWindowState.Minimized
End Sub

Private Sub MaximumToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e


As System.EventArgs) Handles MaximumToolStripMenuItem.Click
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub ExitToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles ExitToolStripMenuItem1.Click
End
End Sub

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


Me.Click
If MouseButtons.Right = Windows.Forms.MouseButtons.Right Then
ContextMenuStrip1.Show()
End If
End Sub
End Class

15) Write a program in C#.Net to create a function to check whether a number is prime or not.
using System;
public class funcexer9
{
public static bool chkprime(int num)
{
for (int i=2; i < num; i++)
if (num %i == 0)
return false;
return true;
}
public static void Main()
{
Console.Write("\n\nFunction : To check a number is prime or not :\n");
Console.Write("-------------------------------------------\n");
Console.Write("Input a number : ");
int n= Convert.ToInt32(Console.ReadLine());

if (chkprime(n))
Console.WriteLine(n+" is a prime number");
else
Console.WriteLine(n+" is not a prime number");
}
}

16) Write a VB.NET program to create Author table (aid, aname, book_ name). Insert the
records (Max 5). Delete a record of author who has written “VB.NET book” and display
remaining records on the data grid view. (Use MS Access to create db.)
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider = MICROSOFT.JET.OLEDB.4.0;data
Source=D:\sym\VB.NET\CRYST\crystdel\Author.mdb")
Dim cmd As New OleDbCommand
Dim ad As New OleDbDataAdapter
Dim ds As New DataSet
Dim rd As OleDbDataReader

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


Handles Button1.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "insert into book values(" & TextBox1.Text & " ,'" & TextBox2.Text
& "','" & TextBox3.Text & "')"
cmd.ExecuteNonQuery()
MsgBox("Record inserted succesfully")
con.Close()
End Sub

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


Handles Button2.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "delete from book where bname='vb'"
cmd.ExecuteNonQuery()
MsgBox("Records deleted succesfully")
con.Close()
End Sub

17) Write a VB.NET program to design following screen, accept the details from the
user. Clicking on Submit button Net Salary should be calculated and displayed into the
Textbox. Display the Messagebox informing the Name and Net Salary of employee.

Public Class EmpProf

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


Handles Button1.Click
txtnetsal.Text = Val(txtsalary.Text) + (Val(txtda.Text) + Val(txthra.Text) - Val(txtit.Text) +
Val(txtma.Text) + Val(txtpf.Text) - Val(txtpt.Text))
MsgBox(txtname.Text + " " + txtnetsal.Text)
End Sub
End Class

18) Write a VB.NET program to accept the details Supplier (SupId, SupName, Phone
No, Address) store it into the database and display it.
Imports System.Data.OleDb
Imports System.Data
Public Class Form1

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


Handles MyBase.Load
DataSet21.Clear()
Me.OleDbDataAdapter1.Fill(DataSet21, "Sup")
End Sub

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


Handles btnfirst.Click
Me.BindingContext(DataSet21, "Sup").Position = 0
End Sub

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


Handles btnprev.Click
Me.BindingContext(DataSet21, "Sup").Position = Me.BindingContext(DataSet21,
"Sup").Position - 1
End Sub

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


Handles btnnext.Click
Me.BindingContext(DataSet21, "Sup").Position = Me.BindingContext(DataSet21,
"Sup").Position + 1
End Sub

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


Handles btnlast.Click
Me.BindingContext(DataSet21, "Sup").Position = Me.BindingContext(DataSet21,
"Sup").Count - 1
End Sub

19) Write a VB.Net program to accept the details of Employee (ENO, EName Salary) and
store it into the database and display it on gridview control.
Imports System.Data.OleDb
Imports System.Data
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load
DataSet11.Clear()
Me.OleDbDataAdapter1.Fill(DataSet11, "Emp")
End Sub

20) Write a VB.NET program to create a table student (Roll No, SName, Class,City). Insert
the records (Max: 5). Update city of students to ‘Pune’ whose city is ‘Mumbai’ and
display updated records in GridView

Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim con As New OleDbConnection("Provider = MICROSOFT.JET.OLEDB.4.0;data
Source=D:\sym\VB.NET\Student.mdb")
Dim cmd As New OleDbCommand

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles btnupdate.Click
con.Open()
cmd.Connection = con
cmd.CommandText = "update stud set stud.city= ‘Pune’ where stud.city='Mumbai' "
cmd.ExecuteNonQuery()
MsgBox("Record updated succesfully")
con.Close()
End Sub
21) Write a VB.NET program to create teacher table (Tid, TName, subject). Insert the
records (Max:5). Search record of a teacher whose name is “Seeta” and display result.

Imports System.Data.OleDb
Imports System.Data
Public Class Form1

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


Handles MyBase.Load
DataSet21.Clear()
Me.OleDbDataAdapter1.Fill(DataSet21, "Teach")
End Sub

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


Handles btnsearch.Click
Dim dv As New DataView(DataSet21.Tables("Teach"))
dv.RowFilter = "tname= '" & TextBox5.Text & "'"
DataGridView1.DataSource = dv
End Sub

You might also like