net practical 1007501070svbitce2010.weebly.com/uploads/8/4/4/5/8445046/final... · web...

28
.Net Practical 1007501070 PRACTICAL-2 PROGRAM-1 AIM: Write a program to generate simple calculator CODE: Public Class Calculator Private Sub btnadd_Click(sender As Object , e As EventArgs ) Handles btnadd.Click txtans.Text = Convert .ToInt32(txta.Text) + txtb.Text End Sub Private Sub btnsub_Click(sender As Object , e As EventArgs ) Handles btnsub.Click txtans.Text = Convert .ToInt32(txta.Text) - txtb.Text End Sub Private Sub btnmul_Click(sender As Object , e As EventArgs ) Handles btnmul.Click txtans.Text = Convert .ToInt32(txta.Text) * txtb.Text End Sub Private Sub btndiv_Click(sender As Object , e As EventArgs ) Handles btndiv.Click txtans.Text = Convert .ToInt32(txta.Text) / txtb.Text End Sub End Class OUTPUT:- 1 | Page

Upload: others

Post on 29-Jan-2021

7 views

Category:

Documents


0 download

TRANSCRIPT

.Net Practical 1007501070

.Net Practical 1007501070

PRACTICAL-2

PROGRAM-1

AIM: Write a program to generate simple calculator

CODE:

Public Class Calculator

Private Sub btnadd_Click(sender As Object, e As EventArgs) Handles btnadd.Click

txtans.Text = Convert.ToInt32(txta.Text) + txtb.Text

End Sub

Private Sub btnsub_Click(sender As Object, e As EventArgs) Handles btnsub.Click

txtans.Text = Convert.ToInt32(txta.Text) - txtb.Text

End Sub

Private Sub btnmul_Click(sender As Object, e As EventArgs) Handles btnmul.Click

txtans.Text = Convert.ToInt32(txta.Text) * txtb.Text

End Sub

Private Sub btndiv_Click(sender As Object, e As EventArgs) Handles btndiv.Click

txtans.Text = Convert.ToInt32(txta.Text) / txtb.Text

End Sub

End Class

OUTPUT:-

PROGRAM-2

AIM: Write a program to generate student’s marksheet.

CODE:

Public Class MARKSHEET

Dim count As Integer = 0

Private Sub ch1_CheckedChanged(sender As Object, e As EventArgs) Handles ch1.CheckedChanged

txt1.Enabled = True

count = count + 1

End Sub

Private Sub ch2_CheckedChanged(sender As Object, e As EventArgs) Handles ch2.CheckedChanged

txt2.Enabled = True

count = count + 1

End Sub

Private Sub ch3_CheckedChanged(sender As Object, e As EventArgs) Handles ch3.CheckedChanged

txt3.Enabled = True

count = count + 1

End Sub

Private Sub ch4_CheckedChanged(sender As Object, e As EventArgs) Handles ch4.CheckedChanged

txt4.Enabled = True

count = count + 1

End Sub

Private Sub btnsub_Click(sender As Object, e As EventArgs) Handles btnsub.Click

txtgt.Text = Val(txt1.Text) + Val(txt2.Text) + Val(txt3.Text) + Val(txt4.Text)

txtp.Text = Val(txtgt.Text) / count

If (txtp.Text <= 35) Then

txtgd.Text = "CC"

ElseIf (txtp.Text <= 50) Then

txtgd.Text = "BC"

ElseIf (txtp.Text <= 60) Then

txtgd.Text = "BB"

ElseIf (txtp.Text <= 70) Then

txtgd.Text = "AB"

ElseIf (txtp.Text > 70) Then

txtgd.Text = "AA"

End If

If (txtp.Text <= 35) Then

txtre.Text = "FAIL"

Else

txtre.Text = "PASS"

End If

End Sub

End Class

OUTPUT:-

PROGRAM-3

AIM: Write a program to generate a tic-tac-toe game.

CODE:

Public Class tic_tac_toe

Dim flag As Boolean = True

Dim ctr1 As Integer = 0

Dim ctr2 As Integer = 0

Private Sub btn1_Click(sender As Object, e As EventArgs) Handles btn1.Click

If flag = True Then

btn1.Text = "0"

flag = False

btn1.Enabled = False

Else

btn1.Text = "X"

flag = True

btn1.Enabled = False

End If

win()

End Sub

Private Sub btn2_Click(sender As Object, e As EventArgs) Handles btn2.Click

If flag = True Then

btn2.Text = "0"

flag = False

btn2.Enabled = False

Else

btn2.Text = "X"

flag = True

btn2.Enabled = False

End If

win()

End Sub

Private Sub btn3_Click(sender As Object, e As EventArgs) Handles btn3.Click

If flag = True Then

btn3.Text = "0"

flag = False

btn3.Enabled = False

Else

btn3.Text = "X"

flag = True

btn3.Enabled = False

End If

win()

End Sub

Private Sub btn4_Click(sender As Object, e As EventArgs) Handles btn4.Click

If flag = True Then

btn4.Text = "0"

flag = False

btn4.Enabled = False

Else

btn4.Text = "X"

flag = True

btn4.Enabled = False

End If

win()

End Sub

Private Sub btn5_Click(sender As Object, e As EventArgs) Handles btn5.Click

If flag = True Then

btn5.Text = "0"

flag = False

btn5.Enabled = False

Else

btn5.Text = "X"

flag = True

btn5.Enabled = False

End If

win()

End Sub

Private Sub btn6_Click(sender As Object, e As EventArgs) Handles btn6.Click

If flag = True Then

btn6.Text = "0"

flag = False

btn1.Enabled = False

Else

btn6.Text = "X"

flag = True

btn6.Enabled = False

End If

win()

End Sub

Private Sub btn7_Click(sender As Object, e As EventArgs) Handles btn7.Click

If flag = True Then

btn7.Text = "0"

flag = False

btn7.Enabled = False

Else

btn7.Text = "X"

flag = True

btn7.Enabled = False

End If

win()

End Sub

Private Sub btn8_Click(sender As Object, e As EventArgs) Handles btn8.Click

If flag = True Then

btn8.Text = "0"

flag = False

btn8.Enabled = False

Else

btn8.Text = "X"

flag = True

btn8.Enabled = False

End If

win()

End Sub

Private Sub btn9_Click(sender As Object, e As EventArgs) Handles btn9.Click

If flag = True Then

btn9.Text = "0"

flag = False

btn9.Enabled = False

Else

btn9.Text = "X"

flag = True

btn9.Enabled = False

End If

win()

End Sub

Sub win()

If (btn1.Text = "0" And btn2.Text = "0" And btn3.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn1.Text = "0" And btn6.Text = "0" And btn7.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn7.Text = "0" And btn8.Text = "0" And btn9.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn3.Text = "0" And btn4.Text = "0" And btn9.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn4.Text = "0" And btn5.Text = "0" And btn6.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn7.Text = "0" And btn8.Text = "0" And btn9.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn1.Text = "0" And btn5.Text = "0" And btn9.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn3.Text = "0" And btn5.Text = "0" And btn7.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn2.Text = "0" And btn5.Text = "0" And btn8.Text = "0") Then

MsgBox("PLAYER1 WON")

ctr1 = ctr1 + 1

ElseIf (btn1.Text = "X" And btn2.Text = "X" And btn3.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn1.Text = "X" And btn6.Text = "X" And btn7.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn3.Text = "X" And btn4.Text = "X" And btn9.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn4.Text = "X" And btn5.Text = "X" And btn6.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn7.Text = "X" And btn8.Text = "X" And btn9.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn1.Text = "X" And btn5.Text = "X" And btn9.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn3.Text = "X" And btn5.Text = "X" And btn7.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

ElseIf (btn2.Text = "X" And btn5.Text = "X" And btn8.Text = "X") Then

MsgBox("PLAYER2 WON")

ctr2 = ctr2 + 1

End If

txtp1.Text = ctr1

txtp2.Text = ctr2

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

btn1.Text = ""

btn1.Enabled = True

btn2.Text = ""

btn2.Enabled = True

btn3.Text = ""

btn3.Enabled = True

btn4.Text = ""

btn4.Enabled = True

btn5.Text = ""

btn5.Enabled = True

btn6.Text = ""

btn6.Enabled = True

btn7.Text = ""

btn7.Enabled = True

btn8.Text = ""

btn8.Enabled = True

btn9.Text = ""

btn9.Enabled = True

End Sub

End Class

OUTPUT:-

PROGRAM-4

AIM: Write a program to generate a Number guessing game.

CODE:

Public Class random_no

Dim var As Integer = 0

Dim n As Integer = 100

Dim count As Integer = 5

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click

Randomize()

var = CInt(Math.Ceiling(Rnd() * n))

txt2.Text = count

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

If (count <> 0) Then

If (Val(txt1.Text) = var) Then

MsgBox("you win")

ElseIf (Val(txt1.Text) > var) Then

MsgBox("your no is bigger")

count = count - 1

txt2.Text = count

txt1.Text = ""

ElseIf (Val(txt1.Text) < var) Then

MsgBox("your no is less")

count = count - 1

txt2.Text = count

txt1.Text = ""

End If

End If

If (count = 0) Then

MsgBox("you loose")

MsgBox(“correct no is:”&var)

End If

End Sub

End Class

OUTPUT:-

PROGRAM-5

AIM: Write a program to create two list boxes ,and selected item move from one list box to other.

CODE:

Public Class Form5

Dim i As Integer = ListBox1.SelectedIndex

Private Sub add_Click(sender As Object, e As EventArgs) Handles add.Click

If (ListBox1.SelectedIndex = 0) Then

ListBox2.Items.Add(ListBox1.SelectedItem)

ListBox1.Items.RemoveAt(0)

End If

If (ListBox1.SelectedIndex = 1) Then

ListBox2.Items.Add(ListBox1.SelectedItem)

ListBox1.Items.RemoveAt(1)

End If

If (ListBox1.SelectedIndex = 2) Then

ListBox2.Items.Add(ListBox1.SelectedItem)

ListBox1.Items.RemoveAt(2)

End If

If (ListBox1.SelectedIndex = 3) Then

ListBox2.Items.Add(ListBox1.SelectedItem)

ListBox1.Items.RemoveAt(3)

End If

End Sub

Private Sub remove_Click(sender As Object, e As EventArgs) Handles remove.Click

If (ListBox2.SelectedIndex = 0) Then

ListBox1.Items.Add(ListBox2.SelectedItem)

ListBox2.Items.RemoveAt(0)

End If

If (ListBox2.SelectedIndex = 1) Then

ListBox1.Items.Add(ListBox2.SelectedItem)

ListBox2.Items.RemoveAt(1)

End If

If (ListBox2.SelectedIndex = 2) Then

ListBox1.Items.Add(ListBox2.SelectedItem)

ListBox2.Items.RemoveAt(2)

End If

If (ListBox2.SelectedIndex = 3) Then

ListBox1.Items.Add(ListBox2.SelectedItem)

ListBox2.Items.RemoveAt(3)

End If

End Sub

Private Sub addall_Click(sender As Object, e As EventArgs) Handles addall.Click

Dim selectedItems = (From i In ListBox1.SelectedItems).ToArray()

For Each selectedItem In selectedItems

ListBox2.Items.Add(selectedItem)

ListBox1.Items.Remove(selectedItem)

Next

End Sub

End Class

OUTPUT:-

PROGRAM-6

AIM: Write a program to create calculator which contains all functionalities that are provided to windows calculator

CODE:

Public Class calculator

Dim count As Integer = 0

Dim ch As Char

Dim bool As Boolean = False

Dim bool0 As Boolean = False

Dim mem As String

Private Sub zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zero.Click

If (bool0 = False) Then

ans.Text = ans.Text + "0"

bool0 = True

ElseIf (ans.Text <> "0") Then

bool0 = False

Else

ans.Text = ans.Text

End If

End Sub

Private Sub one_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles one.Click

ans.Text = ans.Text + "1"

bool0 = False

End Sub

Private Sub two_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles two.Click

ans.Text = ans.Text + "2"

bool0 = False

End Sub

Private Sub three_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles three.Click

ans.Text = ans.Text + "3"

bool0 = False

End Sub

Private Sub four_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles four.Click

ans.Text = ans.Text + "4"

bool0 = False

End Sub

Private Sub five_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles five.Click

ans.Text = ans.Text + "5"

bool0 = False

End Sub

Private Sub six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click

ans.Text = ans.Text + "6"

bool0 = False

End Sub

Private Sub seven_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles seven.Click

ans.Text = ans.Text + "7"

bool0 = False

End Sub

Private Sub eight_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eight.Click

ans.Text = ans.Text + "8"

bool0 = False

End Sub

Private Sub nine_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nine.Click

ans.Text = ans.Text + "9"

bool0 = False

End Sub

Private Sub dot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles dot.Click

If (bool = False) Then

ans.Text = ans.Text + "."

bool = True

End If

End Sub

Private Sub clear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles clear.Click

ans.Text = " "

bool = False

End Sub

Private Sub bk_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles bk.Click

ans.Text = ans.Text.Remove(Len(ans.Text) - 1, 1)

End Sub

Private Sub po_na_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles po_na.Click

Dim flag As Boolean = False

If flag = True Then

ans.Text = "+" + ans.Text

flag = False

Else

ans.Text = "-" + ans.Text

flag = True

End If

End Sub

Private Sub plus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles plus.Click

count = ans.Text

ans.Text = " "

ch = "+"

bool = False

End Sub

Private Sub minus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles minus.Click

count = ans.Text

ans.Text = " "

ch = "-"

bool = False

End Sub

Private Sub multiply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles multiply.Click

count = ans.Text

ans.Text = " "

ch = "*"

bool = False

End Sub

Private Sub divide_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles divide.Click

count = ans.Text

ans.Text = " "

ch = "/"

bool = False

End Sub

Private Sub modulus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles modulus.Click

count = ans.Text

ans.Text = " "

ch = "%"

bool = False

End Sub

Private Sub upon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles upon.Click

count = ans.Text

ans.Text = 1 / count

bool = False

End Sub

Private Sub square_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles square.Click

count = ans.Text

ans.Text = Math.Sqrt(count)

End Sub

Private Sub ms_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ms.Click

mm.Text = "M"

mem = ans.Text

ans.Text = " "

End Sub

Private Sub Mr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Mr.Click

mm.Text = "M"

ans.Text = mem

End Sub

Private Sub mc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mc.Click

mem = " "

ans.Text = " "

mm.Text = " "

End Sub

Private Sub mplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mplus.Click

mm.Text = "M"

ans.Text = ans.Text + CInt(mem)

End Sub

Private Sub eq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles eq.Click

If (ch = "+") Then

ans.Text = count + CInt(ans.Text)

ElseIf (ch = "-") Then

ans.Text = count - CInt(ans.Text)

ElseIf (ch = "*") Then

ans.Text = count * CInt(ans.Text)

ElseIf (ch = "/") Then

ans.Text = count / CInt(ans.Text)

ElseIf (ch = "%") Then

ans.Text = count Mod CInt(ans.Text)

End If

End Sub

End Class

OUTPUT:

PROGRAM-7

AIM: Write a program which demonstrate database connectivity and shows how insert, update , delete and retrieve operations performed on database.

CODE:

Imports System.Data.OleDb

Public Class Form1

Dim con As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\admin\My Documents\Visual Studio 2010\Projects\WindowsApplication8\WindowsApplication8\Employee.mdb")

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

Dim cmd As New OleDbCommand("insert into Emp_det values (" + TexId.Text + ",'" + TexName.Text + "','" + TexAdd.Text + "'," + TexCn.Text + ")", con)

con.Open()

cmd.ExecuteNonQuery()

con.Close()

TexId.Clear()

TexName.Clear()

TexAdd.Clear()

TexCn.Clear()

End Sub

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

Dim cmd As New OleDbCommand(" Update Emp_det set Emp_Name='" + TexName.Text + "',Emp_Address='" + TexAdd.Text + "',Empcn_no=" + TexCn.Text + " where Emp_Id=" + TexId.Text + " ", con)

con.Open()

cmd.ExecuteNonQuery()

con.Close()

TexId.Clear()

TexName.Clear()

TexAdd.Clear()

TexCn.Clear()

End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

Dim cmd As New OleDbCommand(" Delete from Emp_det where Emp_Id=" + TexId.Text + " ", con)

con.Open()

cmd.ExecuteNonQuery()

con.Close()

TexId.Clear()

TexName.Clear()

TexAdd.Clear()

TexCn.Clear()

End Sub

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim cmd As New OleDbCommand(" SELECT * FROM Emp_det where Emp_Id=" + TexId.Text + " ", con

Dim dr As OleDbDataReader

con.Open()

dr = cmd.ExecuteReader()

While (dr.Read())

TexName.Text = dr.GetValue(1)

TexAdd.Text = dr.GetValue(2)

TexCn.Text = dr.GetValue(3)

End While

con.Close()

End Sub

End Class

OUTPUT:-

1)Insert

2)Update

3)Delete

4)Show

PROGRAM-8

AIM: Write an ASP.NET and VB.NET page code that shows the creation of a simple Web Login Page with the database connected in MS Access.

CODE:

1) Default.aspx:

Imports System.Data.OleDb

Partial Class _Default

Inherits System.Web.UI.Page

Protected Sub Login_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login.Click

Dim connect As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\lenovo\Documents\User.accdb"

Dim query As String

query = "Select Count(*) From Users Where Username = ? And UserPassword = ?"

Dim result As Integer = 0

Using conn As New OleDbConnection(connect)

Using cmd As New OleDbCommand(query, conn)

cmd.Parameters.AddWithValue("", UserName.Text)

cmd.Parameters.AddWithValue("", Password.Text)

conn.Open()

Session("User") = UserName.Text

result = DirectCast(cmd.ExecuteScalar(), Integer)

End Using

End Using

If result > 0 Then

Response.Redirect("Default2.aspx")

Else

Literal1.Text = "Invalid credentials"

End If

End Sub

Public ReadOnly Property VerifiedUser() As String

Get

Return UserName.Text

End Get

End Property

End Class

Design View:

Table : “Users” in Access Database

2) Default2.aspx:

Website Output:

1)

2)

3) Error Page:

| Page