Nothing Special   »   [go: up one dir, main page]

VPT Lab-Manual For Students

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 51

HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Haryana Institute of Technology


(Approved by AICTE & Affiliated to MDU Rohtak)

COMPUTER SCIENCE & ENGINEERING


DEPARTMENT

LAB REPORT
(VISUAL PROGRAMMING LAB)

NAME OF STUDENT _________________________________

ROLL No. _________________________________

SEMESTER _________________________________

SESSION _________________________________

STUDENT SIGNATURE_____________ FACULTY SIGNATURE ________________

1
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

This Guide is designed for helping the students to perform better in various practical
Courses. It describes the structure of a good laboratory report, outlines the different
sections of the report and explains the need for each of them. It also introduces some
standard conventions and rules for writing reports of professional quality. The quality
of your written report will strongly affect your grade for the course.

EVALUATION OF PRACTICAL WORK


 Each student will be required to perform the experiment individually.
 Student will be required to write theory, algorithm, program, outputs etc. during
practical session itself.
 Each experiment will be marked by the teacher on the basis of experiment
performed and write up on the same day. These marks will account for 40% of the
sessional marks.
 Sessional marks will also include VIVA and Attendance marks as per rules.

GOOD LABORATORY PRACTICES


 You must develop good laboratory habits by keeping complete laboratory
notebooks.
 Keep all your notes about the lab procedures and data in this notebook in pen.
 It is always better to read experiment in advance.
 The expectation is that you will work individually on separate computers. Each of
you will write a separate report.
 Please bring your lab manual to the lab on every turn.

2
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

THINGS TO DO AND DON’T DO IN THE LAB

DO’S
 Remember this is a practice lab & Keep silence.
 Sit down in proper manner.
 Lab instructor can help you to access software and printer.
 If you require more in depth help you can ask concern lecturer
 Proper shut down the computer system before leaving the lab.
 Exit lab quickly, if short circuit or any emergency occurs.
 You must entry when you enter and leave the lab.

DON’T
 Write any thing on the furniture.
 Delete or change other student’s file.
 Uninstall the any Software.
 Inter change any Hardware.
 Create, Change or remove any password.
 Exhibit disruptive behavior.
 Chatting and other banned sites.
 Play computer games.
 Eat and drink in Lab

3
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

EVALUATION REPORT

Sr. Name of Experiment Date of Experiment Teacher’s


No. Performance Marks Signature
1 Introduction to .Net Framework

2 Design an application that uses the user


defined Dynamic Link Library in VB.NET

3 Design an application that uses the concept of


Graphics in VB.NET

4 Design an Analog Clock using Graphics


features in VB.NET
5 How to you make your own ActiveX control

6 Design an application to Retrive data from


Database using SqlDataAdapter and DataSet
(Sql Server).

7 Design an application that uses the concept of


Dialog Control using VB.Net.

8 Design an application to perform


insertion ,Deletion and Updation in
Database(Sql Server).

9 Design a simple Calculator in VB.Net.

4
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 1 Date: - __/__/____

Aim Introduction to .Net Framework

SOFTWARE:Visual Basic 6.0.NET

CODING/PROCEDURE:

The Microsoft .NET Framework is a software framework that can be installed on


computers running Microsoft Windows operating systems. It includes a large library
of coded solutions to common programming problems and a common language
infrastructure that manages the execution of programs written specifically for the
framework. The .NET Framework supports multiple programming languages in a
manner that allows language interoperability, whereby each language can utilize code
written in other languages; in particular, the .NET library is available to all the
programming languages that .NET encompasses.

The framework's Base Class Library provides a large range of features including user
interface, data access, database connectivity, cryptography, web application
development, numeric algorithms, and network communications. The class library is
used by programmers, who combine it with their own code to produce applications.

Programs written for the .NET Framework execute in a software environment that
manages the program's runtime requirements. Also part of the .NET Framework, this
runtime environment is known as the Common Language Runtime (CLR). The CLR
provides the appearance of an application virtual machine so that programmers need
not consider the capabilities of the specific CPU that will execute the program. The
CLR also provides other important services such as security, memory management,
and exception handling. The class library and the CLR together constitute the .NET
Framework.

The .NET Framework is a Microsoft offering and is intended to be used by most new
applications created for the Windows platform. In order to be able to develop and not
just run applications for the Microsoft .NET Framework 4.0, it is required to have
Microsoft's SDK for Windows 7 or .NET Framework 4 (or newer) or Visual Studio
2010 installed on your computer.

5
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Principal design features:

Interoperability
Because computer systems commonly require interaction between new and
older applications, the .NET Framework provides means to access functionality
that is implemented in programs that execute outside the .NET environment.
Access to COM components is provided in the System.Runtime.InteropServices
and System.EnterpriseServices namespaces of the framework; access to other
functionality is provided using the P/Invoke feature.
Common Runtime Engine
The Common Language Runtime (CLR) is the execution engine of the .NET
Framework. All .NET programs execute under the supervision of the CLR,
guaranteeing certain properties and behaviors in the areas of memory
management, security, and exception handling.

Language Independence
The .NET Framework introduces a Common Type System, or CTS. The CTS
specification defines all possible datatypes and programming constructs
supported by the CLR and how they may or may not interact with each other
conforming to the Common Language Infrastructure (CLI) specification.
Because of this feature, the .NET Framework supports the exchange of types
and object instances between libraries and applications written using any
conforming .NET language.
Base Class Library
The Base Class Library (BCL), part of the Framework Class Library (FCL), is a
library of functionality available to all languages using the .NET Framework.
The BCL provides classes which encapsulate a number of common functions,
including file reading and writing, graphic rendering, database interaction,
XML document manipulation and so on.
Simplified Deployment
The .NET Framework includes design features and tools that help manage the
installation of computer software to ensure that it does not interfere with
previously installed software, and that it conforms to security requirements.
Security
The design is meant to address some of the vulnerabilities, such as buffer
overflows, that have been exploited by malicious software. Additionally, .NET
provides a common security model for all applications.

6
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Portability

The design of the .NET Framework allows it to theoretically be platform


agnostic, and thus cross-platform compatible. That is, a program written to use
the framework should run without change on any type of system for which the
framework is implemented. While Microsoft has never implemented the full
framework on any system except Microsoft Windows, the framework is
engineered to be platform agnostic and cross-platform implementations are
available for other operating systems.

Versions

Version Version Release Visual Studio Default in


Number Date Windows
1.0 1.0.3705.0 2002-02-13 Visual
Studio .NET
1.1 1.1.4322.573 2003-04-24 Visual Windows Server
Studio .NET 2003
2003
2.0 2.0.50727.42 2005-11-07 Visual Studio Windows Server
2005 2003 R2
3.0 3.0.4506.30 2006-11-06 Windows Vista,
Windows Server
2008
3.5 3.5.21022.8 2007-11-19 Visual Studio Windows 7,
2008 Windows Server
2008 R2
4.0 4.0.30319.1 2010-04-12 Visual Studio
2010

7
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Viva Questions:

1.What is Base Class Library ?


2. What is Microsoft .NET Framework ?
3. What is CLR and CLI?

8
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Faculty Signature……………. Date of Submission…………….

9
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 2 Date: - __/__/____

Aim Design an application that uses the user defined Dynamic Link
Library in VB.NET

SOFTWARE USED: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ClassLibrary1;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
int a, b, c;
Class1 o = new Class1();
public Form1()
{
InitializeComponent();
}

// Addition
private void button1_Click(object sender, EventArgs e)
{

a = Int32.Parse(textBox1.Text);
b = Int32.Parse(textBox2.Text);
c = o.add(a,b);
MessageBox.Show("Addition is "+c.ToString());
}
// Subtraction
private void button2_Click(object sender, EventArgs e)
{

10
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

a = Int32.Parse(textBox3.Text);
b = Int32.Parse(textBox4.Text);
c = o.sub(a,b);
MessageBox.Show("Subtraction is " + c.ToString());
}

// Swaping

private void button3_Click(object sender, EventArgs e)


{
a = Int32.Parse(textBox5.Text);
b = Int32.Parse(textBox6.Text);
o.swap(ref a,ref b);
textBox5.Text = a.ToString();
textBox6.Text = b.ToString();
}
// Factorial
private void button4_Click(object sender, EventArgs e)
{
b = Int32.Parse(textBox7.Text);
c=o.fact(b);
MessageBox.Show("Factorial is " + c.ToString());
}

}
}

// Class Library
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ClassLibrary1
{
public class Class1
{
public int add(int a, int b)
{
return (a + b);
}
public int sub(int a, int b)
{
return (a - b);
}
public void swap(ref int a, ref int b)
{

11
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

int c;
c = a;
a = b;
b = c;
}
public int fact(int b)
{
int a = 1;
for (int i = b; i > 0; i--)
{
a = a * i;
}
return a;
}
}
}

12
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

13
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Viva Questions:
1. What is Class Library?
2. What is Object Sender, Event Arguments?

Faculty Signature……………. Date of Submission…………….

14
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 3 Date: - __/__/____

Aim Design an application that uses the concept of Graphics in VB.NET.

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace GraphicsApp
{
public partial class Form1 : Form
{
Graphics g;
int count;
Random rand = new Random();
int rr, gg, bb;
public Form1()
{
InitializeComponent();
}
private void Form1_MouseClick(object sender, MouseEventArgs e)
{
rr = rand.Next(255);
gg = rand.Next(255);
bb = rand.Next(255);
Pen p = new Pen(Color.FromArgb(rr,gg,bb));
if (count < 20)
{
g.DrawEllipse(p, e.X - 40, e.Y - 40, 100, 100);
count++;
}
else
{
MessageBox.Show("No more Circles");

15
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
}
private void Form1_Load(object sender, EventArgs e)
{
g = CreateGraphics();
}
}
}

16
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is using System.ComponentModel?
2. What is using System. Collections.Generic?

Faculty Signature……………. Date of Submission…………….

17
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 4 Date: - __/__/____

Aim Design an Analog Clock using Graphics features in VB.NET

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Analog_Clock
{
public partial class Form1 : Form
{
Graphics g;
float x1, y1,x2,y2,x3,y3,inc1,inc2,inc3,sx,sy,th4;
float th1 = -90 + DateTime.Now.Second*6;
float th2 = -90 + DateTime.Now.Minute * 6 + DateTime.Now.Second * 1.0f / 10;
float th3 = -90 + DateTime.Now.Hour * 30 + DateTime.Now.Minute * 1.0f / 2 +
DateTime.Now.Second * 1.0f / 120;
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)


{
g = CreateGraphics();
timer1.Interval = 1000;
timer1.Start();
}

private void Form1_Paint(object sender, PaintEventArgs e)


{
int i=1;
//g.DrawEllipse(Pens.Black, 250, 100, 500, 500);

18
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

g.DrawEllipse(Pens.Black, 230, 80, 540, 540);


Font f = new Font("Arial",10,FontStyle.Bold);
for (th4 = -60; th4 <= 270; th4 += 30)
{
inc1 = (float)(3.14 / 180) * th4;
sx = (float)(500 + 200 * Math.Cos(inc1))-0.4f;
sy = (float)(350 + 200 * Math.Sin(inc1))+.4f;
g.DrawString(i.ToString(), f, Brushes.Black, sx, sy);
i++;
}
}

private void timer1_Tick(object sender, EventArgs e)


{
Refresh();
th1 += 6;
th2 += 1.0f / 10;
th3 += 1.0f / 120;
inc1 = (float)(3.14 / 180) * th1;
inc2 = (float)(3.14 / 180) * th2;
inc3 = (float)(3.14 / 180) * th3;
x1 = (float)(500 + 200 * Math.Cos(inc1));
y1 = (float)(350 + 200 * Math.Sin(inc1));
x2 = (float)(500 + 160 * Math.Cos(inc2));
y2 = (float)(350 + 160 * Math.Sin(inc2));
x3 = (float)(500 + 100 * Math.Cos(inc3));
y3 = (float)(350 + 100 * Math.Sin(inc3));
g.DrawLine(Pens.Black, 500, 350, x1, y1);
g.DrawLine(Pens.Black, 500, 350, x2, y2);
g.DrawLine(Pens.Black, 500, 350, x3, y3);
}
}
}

19
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is Call by value & Call by Reference?
2. What is PaintEventArguments?

Faculty Signature……………. Date of Submission…………….

20
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 5 Date: - __/__/____

Aim How to you make your own ActiveX control

SOFTWARE: Visual Basic 6.0.NET and Visual C++ 6.0.NET.

CODING/PROCEDURE:

Steps 1: Choose from the menu (in VB.Net) File->New Project.

Steps 2: Select ActiveX Control and press OK.

Steps 3: A new form without a title bar has been opened.

Steps 4: Choose from the menu Project->Project1 Properties.

Steps 5: Change the 'Project Name' to myFirstOCX.

Steps 6: Right click on the form, and choose properties from the menu.

Steps 7: The form's name property by default is UserControl1.Change it to


MyControl.

Steps 8: Add 1 Command Button to your form (named Command1).

21
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Coding:

Dim TextVariable As String

Event Click()
Event KeyPress(KeyAscii As Integer)

Private Sub Command1_Click()


MsgBox (TextVariable)
RaiseEvent Click
End Sub

Private Sub Command1_KeyPress(KeyAscii As Integer)


RaiseEvent KeyPress(KeyAscii)
End Sub

Private Sub UserControl_Resize()


Command1.Width = UserControl.Width
Command1.Height = UserControl.Height
End Sub

Public Property Get Text() As String


Text = TextVariable
End Property

Public Property Let Text(ByVal New_Text As String)


TextVariable = New_Text
PropertyChanged "Text"
End Property

Private Sub UserControl_ReadProperties(PropBag As PropertyBag)


TextVariable = PropBag.ReadProperty("Text", "There is no message")
End Sub

Private Sub UserControl_WriteProperties(PropBag As PropertyBag)


Call PropBag.WriteProperty("Text", TextVariable, "There is no message)
End Sub

Steps 9: Now lets see how the control is working by now.Save the project (File->Save
Project).

22
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Steps 10: Compile the project to OCX Control.From the menu, choose File->Make
MyFirstOCX.ocx and press OK.

Steps 11: Start a new project and enter your control to the project .From the menu
choose Project->Components.

Steps 12: Now you see the new control at the ToolBox.

23
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is ActiveX control?
2. What is KeyAscii?

Faculty Signature……………. Date of Submission…………….

24
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:- 6 Date: - __/__/____

Aim Design an application to Retrive data from Database using


SqlDataAdapter and DataSet.

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
sqlConnection1.Open();
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = "insert into student values('" + textBox1.Text + "','" +
textBox2.Text + "','" + comboBox1.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
sqlCommand1.ExecuteNonQuery();
MessageBox.Show("Data Inserted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);

25
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
sqlConnection1.Close();
}

private void button2_Click(object sender, EventArgs e)


{
Form2 f = new Form2();
f.Show();
}
}
}

// Table Data
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication3
{
public partial class Form2 : Form
{
int i;
SqlDataAdapter da;
DataSet ds = new DataSet();
public Form2()
{
InitializeComponent();
}

private void Form2_Load(object sender, EventArgs e)


{
sqlConnection1.Open();
}

private void button1_Click(object sender, EventArgs e)


{
try
{
da = new SqlDataAdapter("select * from student", sqlConnection1);
da.Fill(ds);
if (ds.Tables[0].Rows.Count != 0)
{

26
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

label6.Text = ds.Tables[0].Rows[i].ItemArray[0].ToString();
label7.Text = ds.Tables[0].Rows[i].ItemArray[1].ToString();
label8.Text = ds.Tables[0].Rows[i].ItemArray[2].ToString();
label9.Text = ds.Tables[0].Rows[i].ItemArray[3].ToString();
label10.Text = ds.Tables[0].Rows[i].ItemArray[4].ToString();
}
i++;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
sqlConnection1.Close();
}
}
}

27
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is Database and SQl Server?
2. What is Dataset?

Faculty Signature……………. Date of Submission…………….

28
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:-7 Date: - __/__/____

Aim Design an application that uses the concept of Dialog Control using
VB.Net

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (openFileDialog1.ShowDialog() != DialogResult.Cancel)
MessageBox.Show(openFileDialog1.FileName);
listBox1.Items.Add(openFileDialog1.FileName);

private void listBox1_SelectedIndexChanged(object sender, EventArgs e)


{
pictureBox1.Image = Image.FromFile(listBox1.SelectedItem.ToString());
}

private void button2_Click(object sender, EventArgs e)


{
if (listBox1.Items.Count > 0)

29
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

{
timer1.Start();
}
else
{
MessageBox.Show("Please Select Address");
}
}
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
if (i < listBox1.Items.Count)
{
pictureBox1.Image = Image.FromFile(listBox1.Items[i].ToString());
i++;
}
else
{
i = 0;
}
}

private void Form1_Load(object sender, EventArgs e)


{
timer1.Stop();
}
}
}

30
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is Dialog Control?
2. What is Namespace ?

Faculty Signature……………. Date of Submission…………….

31
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

32
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:-8 Date: - __/__/____

Aim Design an application to perform insertion ,Deletion and Updation


in Database.

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Insertion
private void button1_Click(object sender, EventArgs e)
{
try
{
sqlConnection1.Open();
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = "insert into student values('" + textBox1.Text + "','" +
textBox2.Text+ "','" + comboBox1.Text + "','" + textBox3.Text + "','" + textBox4.Text + "')";
sqlCommand1.ExecuteNonQuery();
MessageBox.Show("Data Inserted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}

33
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

sqlConnection1.Close();
}
// Updation
private void button2_Click(object sender, EventArgs e)
{
try
{
sqlConnection1.Open();
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = "update student set Address='"+textBox4.Text+"' where
(Roll='"+textBox1.Text+"')";
sqlCommand1.ExecuteNonQuery();
MessageBox.Show("Data Updated");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
sqlConnection1.Close();
}
// Deletion
private void button3_Click(object sender, EventArgs e)
{
try
{
sqlConnection1.Open();
sqlCommand1.Connection = sqlConnection1;
sqlCommand1.CommandText = "delete from student where (Roll='"+textBox1.Text+"')";
sqlCommand1.ExecuteNonQuery();
MessageBox.Show("Data Deleted");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
sqlConnection1.Close();
}
}
}

34
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is Sql Server& SqlDataAdapter ?
2. What is Data Grid ?

Faculty Signature……………. Date of Submission…………….

35
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Experiment No.:9 Date: - __/__/____

Aim Design a simple Calculator in VB.Net.

SOFTWARE: Visual Basic 6.0.NET

CODING/PROCEDURE:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Calculator
{
public partial class Form1 : Form
{
int status = 0,st=0;
double res, num1;
String opstate;
public Form1()
{
InitializeComponent();
}

private void button7_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length<12)
{
textBox1.Text = "7";

status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "7";
}
}

36
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

private void button3_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "3";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "3";
}
}

private void button9_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "9";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "9";
}
}

private void button8_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "8";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "8";
}
}

private void button6_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "6";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{

37
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

textBox1.Text = textBox1.Text + "6";


}
}

private void button5_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "5";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "5";
}
}

private void button4_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "4";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "4";
}
}

private void button2_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "2";
status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "2";
}
}

private void button1_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "1";

38
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

status = 1;
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "1";
}
}

private void button10_Click(object sender, EventArgs e)


{
if (status == 0 && textBox1.Text.Length < 12)
{
textBox1.Text = "0";
}
else if (status == 1 && textBox1.Text.Length < 12)
{
textBox1.Text = textBox1.Text + "0";
}
}

private void button15_Click(object sender, EventArgs e)


{
textBox1.Text = "0";
st = status = 0;
res = num1 = 0.0;
opstate = "";
}

private void button16_Click(object sender, EventArgs e)


{
if (st == 0 && status == 1)
{
num1 = Int32.Parse(textBox1.Text);
status = 0;
st++;
}
else if (st == 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = num1 + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{

39
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

res = num1 - Int32.Parse(textBox1.Text);


textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = num1 * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{
res = num1 / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
st++;
}
else if (st > 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = res + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{
res = res - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = res * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{

40
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

res = res / Int32.Parse(textBox1.Text);


textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
}
else
{
textBox1.Text = res.ToString();
}
opstate = "plus";
}

private void button11_Click(object sender, EventArgs e)


{
if (status == 1)
{
switch (opstate)
{
case "plus":
{
if (st == 1)
{
res = num1 + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
else if (st > 1)
{
res = res + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
break;
}
case "minus":
{
if (st == 1)
{
res = num1 - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
else if (st > 1)
{
res = res - Int32.Parse(textBox1.Text);

41
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

textBox1.Text = res.ToString();
}
break;
}
case "mul":
{
if (st == 1)
{
res = num1 * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
else if (st > 1)
{
res = res * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
break;
}
case "div":
{
if (st == 1)
{
res = num1 / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
else if (st > 0)
{
res = res / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
}
break;
}
default:
{
break;
}
}
}
opstate = "";
}

private void button12_Click(object sender, EventArgs e)


{
if (st == 0 && status == 1)
{
num1 = Int32.Parse(textBox1.Text);
status = 0;
st++;

42
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
else if (st == 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = num1 + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{
res = num1 - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = num1 * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{
res = num1 / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
st++;
}
else if (st >= 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = res + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":

43
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

{
res = res - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = res * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{
res = res / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
}
else
{
textBox1.Text = res.ToString();
}
opstate="minus";
}

private void button13_Click(object sender, EventArgs e)


{
if (st == 0 && status == 1)
{
num1 = Int32.Parse(textBox1.Text);
status = 0;
st++;
}
else if (st == 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = num1 + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;

44
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
case "minus":
{
res = num1 - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = num1 * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{
res = num1 / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
st++;
}
else if (st > 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = res + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{
res = res - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = res * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;

45
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
case "div":
{
res = res / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
}
else
{
textBox1.Text = res.ToString();
}
opstate = "mul";
}

private void button14_Click(object sender, EventArgs e)


{
if (st == 0 && status == 1)
{
num1 = Int32.Parse(textBox1.Text);
status = 0;
st++;
}
else if (st == 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = num1 + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{
res = num1 - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = num1 * Int32.Parse(textBox1.Text);

46
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

textBox1.Text = res.ToString();
break;
}
case "div":
{
res = num1 / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;
}
}
status = 0;
st++;
}
else if (st > 1 && status == 1)
{
switch (opstate)
{
case "plus":
{
res = res + Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "minus":
{
res = res - Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "mul":
{
res = res * Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
case "div":
{
res = res / Int32.Parse(textBox1.Text);
textBox1.Text = res.ToString();
break;
}
default:
{
break;

47
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
}
status = 0;
}
else
{
textBox1.Text = res.ToString();
}
opstate = "div";
}

private void groupBox1_Enter(object sender, EventArgs e)


{

private void button17_Click(object sender, EventArgs e)


{
int t = Int32.Parse(textBox1.Text);
t = t / 10;
textBox1.Text = t.ToString();
}

private void button18_Click(object sender, EventArgs e)


{
res = Math.Sqrt(Int32.Parse(textBox1.Text));
textBox1.Text = res.ToString();
status = 0;
st = 1;
}

private void textBox1_TextChanged(object sender, EventArgs e)


{

private void Form1_Load(object sender, EventArgs e)


{
textBox1.Focus();
}

private void Form1_KeyPress(object sender, KeyPressEventArgs e)


{

private void textBox1_KeyPress(object sender, KeyPressEventArgs e)


{

48
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

}
}
}

49
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

Result :-

Viva Questions:
1. What is Conditional Statements?
2. What is System.Windows.Forms ?

Faculty Signature……………. Date of Submission…………….

50
HARYANA INSTITUTE OF TECHNOLOGY VISUAL PROGRAMMING LAB (CSE-312-F)

51

You might also like