2 by Sachinraj

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

Homework 4

CAP 407
MODERN PROGRAMMING TOOLS & TECHNIQUES III

SUBMITTED TO-
Sarabjit Sir

SUBMITTED BY-
SACHIN RAJ
B34
D3901
PART- A
Q 1. Create a window based application to display a message box
with Yes/No/Cancel buttons, icon of warning. Perform different
operations when user clicks on “Yes”, “No” and “Cancel” using
dialog result.
Ans-
Public Class Form1

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


As System.EventArgs) Handles Button1.Click
Dim result = MessageBox.Show("message", "caption",
MessageBoxButtons.YesNoCancel)
If result = DialogResult.Cancel Then
MessageBox.Show("Cancel pressed")
ElseIf result = DialogResult.No Then
MessageBox.Show("No pressed")
ElseIf result = DialogResult.Yes Then
MessageBox.Show("Yes pressed")
End If

End Sub
End Class
Q 2. Create a windows based application to read student_name,
reg_no, date of admission, graduate and undergraduate_course
using textbox, date and time picker, radio button etc. Store
these data in file and display the same from file? (Using Text
Mode)
Ans-
Imports System.IO

Public Class Form1


Inherits System.Windows.Forms.Form

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


As System.EventArgs) Handles Label3.Click

End Sub

Private Sub CheckBox1_CheckedChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
CheckBox1.CheckedChanged
If CheckBox1.CheckState = CheckState.Checked Then
MessageBox.Show("U Are Graduate")
End If
End Sub

Private Sub CheckBox2_CheckedChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
CheckBox2.CheckedChanged

If CheckBox2.CheckState = CheckState.Checked Then

MessageBox.Show("UnGraduate Man")
End If
End Sub

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


As System.EventArgs) Handles Button1.Click
Dim fs As New FileStream("d:\binary1.txt", FileMode.Create,
FileAccess.Write)
Dim bwritter As New BinaryWriter(fs)
bwritter.Write(TextBox1.Text)
bwritter.Write(TextBox2.Text)
bwritter.Write(TextBox3.Text)
bwritter.Write(CheckBox1.Text)
bwritter.Write(CheckBox2.Text)
bwritter.Write(DateTimePicker1.Text)
fs.Close()
MessageBox.Show("information Stored")
TextBox1.Text = ""

End Sub

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


As System.EventArgs) Handles Button2.Click
Dim fs As New FileStream("d:\binary1.txt", FileMode.Open,
FileAccess.Read)
Dim breader As New BinaryReader(fs)
TextBox1.Text = breader.Read()
TextBox2.Text = breader.Read()
TextBox3.Text = breader.Read()
CheckBox1.Text = breader.Read()
CheckBox2.Text = breader.Read()
breader.Close()
fs.Close()
TextBox1.Text = ""
End Sub

Private Sub DateTimePicker1_ValueChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
DateTimePicker1.ValueChanged

End Sub
End Class

Q 3. Write a program with following specifications for a student


Reg. No., Student Name class, Marks in three subjects. This data
should be stored in a table by taking values from user using
textboxes, Radio buttons etc. Program should display student
details, calculate aggregate percentage & Grades using following
rules:

Marks < 30 Grade F


Marks > 30 & marks < 40 Grade D
Marks > 40 & marks < 60 Grade C
Marks > 60 & marks < 80 Grade B
Marks > 80 Grade A
Program should fetch data from table(s), display all the above
information & store these salary details in the table.
Ans-
Imports System.IO
Imports System.Data.Odbc
Public Class Form1
Dim con As New OdbcConnection("dsn=student")

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


As System.EventArgs) Handles Button1.Click
Dim a, b As Integer
a = Convert.ToInt32(TextBox3.Text) +
Convert.ToInt32(TextBox4.Text) + Convert.ToInt32(TextBox5.Text)
b=a/3
TextBox6.Text = ("Marks is" & a)
TextBox7.Text = ("percentage is" & b)
If a < 30 Then
TextBox8.Text = ("F")
ElseIf a > 30 And a < 40 Then
TextBox8.Text = ("D")
ElseIf a > 40 And a < 60 Then
TextBox8.Text = ("C")
ElseIf a > 80 Then
TextBox8.Text = ("A")

End If

End Sub

Private Sub TextBox6_TextChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
TextBox6.TextChanged

End Sub

Private Sub TextBox7_TextChanged(ByVal sender As


System.Object, ByVal e As System.EventArgs) Handles
TextBox7.TextChanged

End Sub

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


As System.EventArgs) Handles Button2.Click

con.Open()

Dim qry As String


qry = "insert into
sachinraj(Sname,Regno,Marks1,Marks2,Marks3,Total,Percentage,Grade
)values (' " + TextBox1.Text + " ',' " + TextBox2.Text + " ',' " +
TextBox3.Text + " ',' " + TextBox4.Text + " ',' " + TextBox5.Text + "
',' " + TextBox6.Text + " ',' " + TextBox7.Text + " ',,' " +
TextBox8.Text + " ')"
Dim com As New OdbcCommand(qry, con)
com.ExecuteNonQuery()
MessageBox.Show("One Record Inserted")

con.Close()

End Sub
End Class
Database Table
PART –B

Q 4. Create a window based application in vb.net to calculate


salary of an employee by reading Emp_ID, Employee Name,
Basic Salary, gender. This information should be stored in a
table by reading values from user using textboxes, Radio
buttons etc. Program should calculate total salary using
following rules:
Total Salary= Basic Salary + DA + HRA + Medical
D.A. = 54% of Basic Salary
H.R.A. = 5% of Basic Salary
PF = 10% of Basic Salary
Medical= Rs. 1000
Ans-
Public Class Form1

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


As System.EventArgs) Handles Button1.Click

Dim Da As Double = 5.4 * TextBox1.Text


Dim Hra As Double = 0.05 * TextBox1.Text

Dim Pf As Double = 0.1 * TextBox1.Text

Dim Med As Integer = 1000

TextBox2.Text = Convert.ToInt32(TextBox1.Text) + Da + Hra +


Pf + Med

End Sub
Q 5. Create a window based application to read data of a student
for placement registration. Send this data to a file and read it
from same file. (Using Binary Mode)
Ans-

Imports System.IO
Public Class Form1
Inherits System.Windows.Forms.Form
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
TextBox1.Focus()
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button1.Click
Dim fs As New FileStream("d:\Binary1.txt", FileMode.Create,
FileAccess.Write)
Dim bwriter As New BinaryWriter(fs)
bwriter.Write(TextBox1.Text)
MessageBox.Show("Your file has been saved...")
fs.Close()
TextBox1.Text = ""
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles Button2.Click
Dim fs As New FileStream("d:\Binary1.txt", FileMode.Open,
FileAccess.Read)
Dim breader As New BinaryReader(fs)
TextBox2.Text = breader.Read()
breader.Close()
fs.Close()
End Sub

End Class
Q 6. Create a window based application to read & write data of a
patient in a XML file and read it from same file using fields
like

Reg.no.
Patient Name
Dr. Reffered
Diagnose
Ans-
Imports System.Xml
Public Class Form1

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


As System.EventArgs) Handles Button1.Click
Dim writer As New XmlTextWriter("d:b.xml", Nothing)
writer.WriteStartDocument()

writer.WriteStartElement("root")
writer.WriteStartElement("r", "RECORD", "urn:record")
writer.WriteStartElement("Patient Registration number:", "")
writer.WriteString("10902778")
writer.WriteStartElement("Paitent Name:", "")
writer.WriteString(" Navneet Mishra")
writer.WriteStartElement("Doctor Refered:", "")
writer.WriteString(" Anuj Mehta")
writer.WriteStartElement("Diagnose:", "")
writer.WriteString(" Eye Problem ")
writer.WriteEndElement()
writer.WriteEndDocument()
writer.Close()
MessageBox.Show("File Has Been Created In Ur Drive")
End Sub

End Class

You might also like