Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 141

Title

Student Information
Management System
Project
By:Vikas

2010
Introduction

The Student Information Management System is a program to manage the records of

students. It is designed to make record keeping and grading much easier. It is useful for

educational institutes, universities, colleges, etc.

It maintains the following information about students: name, roll-no, course taken, date

of birth, address info, result of each student, etc. The software also maintains the

database of teachers, the courses offered by the institute, subjects under a particular

course, subject wise & overall result of the student. The software allows the user to print

records of students, teachers, and courses offered by the institute.

2
Principle Objective

The objective of this project is to develop a student information management system

that allows the educational institutes, colleges, & universities to easily maintain the

records of students. It provides the following features:

 Easy maintenance and management.

 Intelligent & Interactive user interface

 It maintains a list of active users.

 It maintains a list of all the students.

 It maintains the database of teachers.

 It maintains the database of all the courses offered by the institute.

 It maintains the database of subjects under a particular course.

 It maintains the subject wise & overall result of students.

 It allows the user to print the list of students, courses, & teachers.

3
Project Category

This project falls under the following category:

 RDBMS

 Business Applications

4
Tools/Platform, Languages to be used

 Visual Basic 6

 SQL Server

Operating System

Windows

Requirements Hardware

Pentium-4

512 MB RAM

5
System Analysis

6
Feasibility Study

Not everything imaginable is feasible. Software feasibility has some solid dimensions:

 Technical Feasibility: Is a project technically feasible? Is it within the state of

the art? Can defects be reduced to a level matching the application's needs?

 Financial Feasibility: Is it financially feasible? Can development be completed

at a cost the software organization, its client, or the market can afford?

 Time Feasibility: Will the project's time to market beat the competition?

 Resource Feasibility: Does the organization have the resources needed to

succeed?

 Legal Feasibility: Legal feasibility is the determination of any infringement,

violation, or the liability that could result from the development of the system. The

Student database management system is the collection of records of students,

teachers, courses, subjects, etc. Hence our system is legally feasible.

 Management Feasibility: The management is always interested in the system

that can provide more efficiency at a lower cost. Our system is made for

institutes, universities, colleges, etc. It is designed to make record keeping and

grading much easier.

Software Engineering Paradigm

In this project, we have applied the RAD (Rapid application development) Model.
7
Rapid application development is an incremental software development process model

that emphasizes an extremely short development cycle. The RAD model is a high

speed adaptation of the linear sequential model in which rapid development is achieved

by using component based construction. If requirements are well understood and

project scope is constrained, the RAD process enables a development team to create a

fully functional system within very short time periods (e.g., 60 to 90 days). The RAD

approach encompasses the following phases:

Business modeling: The information flow is modeled in a way that answers the

following questions: What information drives the business process? What information is

generated & Who generates it? etc.

Data modeling: The information flow defined as part of the business modeling phase is

refined into a set of data objects needed to support the business. The characteristics of

each object are identified & the relationship between these objects defined.

Process modeling: The data objects defined in the data modeling phase are

transformed to achieve the information flow necessary to implement a business

function. Processing descriptions are created for adding, modifying, deleting, or

retrieving a data object.

Application generation: RAD process works to reuse existing program components or

create reusable components.

8
Testing & turnover: Since the RAD process emphasizes reuse, many of the program

components have already been tested. This reduces overall testing time.

9
Analysis Reports

10
Context Analysis Diagram

11
First level Diagram

12
Second Level Diagram

13
Third Level Diagram

14
Third level Diagram

15
ERD

16
Program Structure

17
Modules

Functionally the project has been divided into the following parts:

Students: This is the main module of the project. It allows the user to view student's

records. It provides an easy to use interface to add, delete, & edit student information in

the database. This module shows all the student's name in a data grid. It shows user

the following information about students: Roll number, first & last name, course taken,

date of birth, fathers name, e-mail, phone number, & address information. This module

gets data from the student and course database.

Users: It maintains the list of different users. Different features are available for different

users. A user can be of the following types: administrator, teacher, or student. Different

operations are allowed to different users. The administrator is responsible for creating

the user.

Teachers: The Student Information Management System maintains a list of teachers. It

allows to view, add, edit, & delete details of teachers. This module maintains the

following information about teachers: Teacher ID, name, & addressing information. The

management can easily check and edit the list of teachers. This module gets/stores

data from/into the teacher database.

18
Courses: The software has a list of courses offered by the institute. The list provides

the following information about a course: Course ID, course name. For example, MCA is

the course ID and the course name is Master in computer applications. BCA (bachelor

in computer applications). This module gets/stores data from/into the course database.

Subjects: This module contains details of subjects under a particular course. It

maintains the following information: Subject ID, subject name, course under which this

subject is available, & the teacher who teaches this subject. The information must be

first entered into the database. The operator can easily enter the records into the

database.

Result: This module provides subject wise result & overall result of the student. It

provides details of marks obtained by a student in a particular subject & it also shows

the overall percentage, & grade of the student. Result information can be easily added,

edited & deleted from the database. Teachers can easily view the student grades and

edit them.

Reports: This module is responsible for generating & printing reports like student's

report, teacher report, & courses report. It can easily print several professionally looking

reports. To generate reports the reports module gets data from the teacher, student,

course database.

19
Search: This module is responsible for searching the students. It provides an easy to

use interface to search student records. It allows the user to search the records on the

basis of roll number and the student name. After searching the records the user can

easily upgrade information.

20
Tables

Tables

Student

Name Description Data Type


The unique roll number of the student. (Primary
RollNo nvarchar(10)
Key)
FirstName First name of the student. nvarchar(25)
LastName Last name of the student. nvarchar(25)
The course taken by the student. (Foreign key,
CourseID nvarchar(5)
references CourseID in the Course table)
DOB Date of birth of the student. smalldatetime
FatherName The name of students father. nvarchar(50)
PhoneNumber The phone number provided by the student nvarchar(15)
Address The address of the student nvarchar(200)
City City where the student resides nvarchar(25)
State State related details nvarchar(25)
PostalCode Pin code nvarchar(15)

Teacher

Name Description Data Type


TeacherID Unique ID of the teacher (Primary key) nvarchar(6)
Name The name of the teacher nvarchar(50)
Address The address of the teacher nvarchar(200)
City City where the teacher resides nvarchar(25)
State State related details nvarchar(25)
PhoneNumber The phone number of the teacher nvarchar(15)

Users
Name Description Data Type
UserName The user name (PK) varchar (8)
Password Password for login varchar (8)
Type Type of user Integer

21
Course

Name Description Data Type


CourseID The unique course ID (Primary key) nvarchar(5)
Course Name of the course nvarchar(50)

Subject

Name Description Data Type


SubjectID Unique ID of subject (Primary Key) nvarchar(5)
SubjectName Full name of the subject nvarchar(50)
The course name (Foreign key,

CourseID references CoursesID in the Course nvarchar(5)

table)
The teacher who teaches this subject

TeacherID (Foreign key, references TeacherID in nvarchar(6)

the Teacher table)

Result

Name Description Data Type


Roll number of the student (Foreign key,
RollNo nvarchar(10)
references RollNo in the Student table)
Subject name (Foreign key, references
SubjectID nvarchar(5)
SubjectID in the Subject table)
Marks of the student in a particular
Marks Integer
subject.
Status of the subject. If the status is

"SC", it means successfully completed. If


Status nvarchar(2)
the status is "NC", it means not

completed.

22
Process Specification
The overall description of the Student process requires understanding the physical

location of the program and application being stored in the physical machines. The

description is as follows:

The data of this project can be stored on the same computer or on a different server.

When the program starts it checks for database availability. If it is available it will

connect to the database otherwise the application will close. The server administrator is

responsible for starting the database server.

23
The process gets activated by a file named " mainModule.bas ". This invokes a

procedure called main. The function connects the software to the database. It opens

the connection with the following line:

studentsCon.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial


Catalog=studentdata"

If it is unable to connect to the database it shows a user friendly message and closes

the application. After successfully connecting to the database it shows the main screen

which contains all the menus to open different forms.

24
Reports

Lists all the reports generated by the system.

 Teachers Report

 Students Report

 Courses Report

Each of these reports can be easily printed.

25
System Screens

26
The Main Screen

This screen is the main screen of the student information management system. It

contains all the menus for viewing, adding, editing, & deleting records of students,

teachers, subjects, courses, & result.

27
The Students List Screen

This screen shows the list of all students. It provides the details like: roll no, name,

father name, Date of birth, phone number, course selected, address info, etc.

28
The Students Screen- Add Record Mode

This screen allows the user to add details about a new student.

29
The Students Screen- Edit Record Mode

This screen allows the user to edit information about students.

30
The Students Screen- Delete Record Mode

This screen allows the user to delete records of students.

31
The Courses List Screen

This screen shows all the courses currently available. It allows the user to add, edit, &

delete course-related information.

32
The Subjects List Screen

This screen shows the list of subjects. The subjects are organized by course.

33
The Teachers List Screen

This screen shows details about teachers.

34
The Result of all Students Screen

This screen shows the subject wise marks of students.

35
The Result by Roll Number Screen

This screen shows the result of a particular student.

36
The Teachers Report

37
The Students Report

38
The Courses Report

39
Menus

The Student Menu

1. To add a new student in the database

2. To edit information about students

3. To delete student records

4. To show/hide a list of all the students

The Result Menu

1. Shows the result of a particular student.

2. Shows the subject wise result of all students.

40
The Listing Menu

1. Shows a list of all the teachers

2. Shows a list of all the courses available

3. Shows a list of all the subjects

The Reports Menu

1. Shows the students report.

2. Shows the courses report.

3. Shows the teachers report.

41
CODE

42
The general Module – mainModule

Public studentsCon As ADODB.Connection

Public Sub main()


Call connectDatabase
frmMain.Show
End Sub

Public Function connectDatabase()


On Error GoTo errCheck:
Set studentsCon = New ADODB.Connection
studentsCon.CursorLocation = adUseClient
studentsCon.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security
Info=False;Initial Catalog=studentdata"
Exit Function
errCheck:
MsgBox Err.Description
MsgBox "The application will be closed."
End
End Function

Public Function closeConnection()


studentsCon.Close
End Function

43
The Main Screen – frmMain

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim adoPrimaryRS As ADODB.Recordset

Private Sub Form_Load()


'set the connection to the main connection
Set db = studentsCon
Call InitializeControls
End Sub
'procedure to resize the grid
Private Sub Form_Resize()
On Error Resume Next
dgrid.Width = Me.Width - 350
dgrid.Height = Me.Height - 950
lblTitle.Top = Me.Height / 2 - lblTitle.Height / 2 - 200
lblTitle.Left = Me.Width / 2 - lblTitle.Width / 2
End Sub
'initialize the controls on the form
Private Sub InitializeControls()
'set the forecolor of the title label
lblTitle.ForeColor = RGB(211, 211, 211)
End Sub
'initialize the grid on the form
Private Sub InitializeGrid()
Set adoPrimaryRS = New ADODB.Recordset
adoPrimaryRS.Open "select * from Student Order by RollNo", db, adOpenForwardOnly,
adLockReadOnly

''''Data Grid settings

'don't allow the user to add new records


'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
44
dgrid.AllowUpdate = False
dgrid.Font.Name = "Verdana"
dgrid.Font.Size = 8

'set column 0 caption


dgrid.Columns(0).Caption = "Roll No"
'bind the column to a datafield
dgrid.Columns(0).DataField = "RollNo"
dgrid.Columns(1).Caption = "First Name"
dgrid.Columns(1).DataField = "FirstName"
dgrid.Columns.Add 2
dgrid.Columns(2).Caption = "Last Name"
dgrid.Columns(2).DataField = "LastName"
dgrid.Columns.Add 3
dgrid.Columns(3).Caption = "Course"
dgrid.Columns(3).DataField = "CourseID"

dgrid.Columns.Add 4
dgrid.Columns(4).Caption = "DOB"
dgrid.Columns(4).DataField = "DOB"

dgrid.Columns.Add 5
dgrid.Columns(5).Caption = "Father Name"
dgrid.Columns(5).DataField = "FatherName"

dgrid.Columns.Add 6
dgrid.Columns(6).Caption = "Phone No"
dgrid.Columns(6).DataField = "PhoneNumber"

dgrid.Columns.Add 7
dgrid.Columns(7).Caption = "Email"
dgrid.Columns(7).DataField = "Email"

dgrid.Columns.Add 8
dgrid.Columns(8).Caption = "Address"
dgrid.Columns(8).DataField = "Address"

dgrid.Columns.Add 9
dgrid.Columns(9).Caption = "City"
dgrid.Columns(9).DataField = "City"

dgrid.Columns.Add 10
dgrid.Columns(10).Caption = "State"
dgrid.Columns(10).DataField = "State"

45
dgrid.Columns.Add 11
dgrid.Columns(11).Caption = "Pin"
dgrid.Columns(11).DataField = "PostalCode"

'set the width of columns


dgrid.Columns(0).Width = 1100
dgrid.Columns(1).Width = 1000
dgrid.Columns(2).Width = 1000
dgrid.Columns(3).Width = 700
dgrid.Columns(4).Width = 1200
dgrid.Columns(5).Width = 1200
dgrid.Columns(6).Width = 1200
dgrid.Columns(7).Width = 1800
dgrid.Columns(8).Width = 1500
dgrid.Columns(9).Width = 800
dgrid.Columns(10).Width = 800
dgrid.Columns(11).Width = 900
Set dgrid.DataSource = adoPrimaryRS
End Sub

Private Sub Form_Unload(Cancel As Integer)


'close the connection with the database
Call closeConnection
End
End Sub

'menu for course list


Private Sub mnuCoursesList_Click()
frmCourse.Show 0, Me
End Sub

'this procedure shows the student form


' in the add new mode
Private Sub mnuitmAdd_Click()
'if the form is already visible then
'exit the procedure
If frmStudent.Visible = True Then Exit Sub
'else show the form
frmStudent.Show 0, Me
'open the form in the add new mode
frmStudent.cmdAdd_Click
End Sub

'allows the user to delete student records


46
Private Sub mnuitmDelete_Click()
If frmStudent.Visible = True Then Exit Sub
'show the form with list
frmStudent.cmdList_Click
frmStudent.Show 0, Me
'set focus on the delete button
frmStudent.cmdDelete.SetFocus
End Sub
'allw the users to edit a student record
Private Sub mnuitmEdit_Click()
If frmStudent.Visible = True Then Exit Sub
'show the form with list
frmStudent.cmdList_Click
frmStudent.Show 0, Me
'allow the users to edit a record
frmStudent.cmdEdit_Click
End Sub
'shows the result form
Private Sub mnuitmResultAll_Click()
frmResult.Show 0, Me
End Sub
'shows the result by roll number form
Private Sub mnuitmResultbyRoll_Click()
frmgetResult.Show 0, Me
End Sub
'show the details of all the students in the main window
Private Sub mnuitmStudentList_Click()
If mnuitmStudentList.Checked = False Then
'set the mouse pointer to hourglass
Me.MousePointer = vbHourglass
'initialize the grid
Call InitializeGrid
'show the grid
dgrid.Visible = True
'agin set the default pointer
Me.MousePointer = vbDefault
'set the menu as checked
Me.mnuitmStudentList.Checked = True
Else
'hide the grid
dgrid.Visible = False
'set its datasource to nothing
Set dgrid.DataSource = Nothing
'uncheck the menu item
Me.mnuitmStudentList.Checked = False
47
End If
End Sub
'show the course report
Private Sub mnurptCourses_Click()
rptCourse.Show 0, Me
End Sub

'show the student report


Private Sub mnurptStudents_Click()
rptStudent.Show 0, Me
End Sub

'show the teacher report


Private Sub mnurptTeachers_Click()
rptTeacher.Show 0, Me
End Sub

'show all the subjects available


Private Sub mnuSubjectsList_Click()
frmSubject.Show 0, Me
End Sub
'show the details of all teachers
Private Sub mnuTeachersList_Click()
frmTeacher.Show 0, Me
End Sub

48
The Course Screen- frmCourse

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim WithEvents adoPrimaryRS As ADODB.Recordset
'variable to bookmark current location
Dim mvBookMark As Variant
'variable for editing
Dim mbEditFlag As Boolean
'variable for adding new records
Dim mbAddNewFlag As Boolean
'flag for data changes
Dim mbDataChanged As Boolean

'show/hide all records grid


Private Sub cmdList_Click()
'shows all the records in a grid
If cmdList.Caption = "List" Then
cmdList.Caption = "Hide"
cmdList.ToolTipText = "Hide List"
'resize the window
Me.Height = Me.Height + dgrid.Height + 150
'Bind the data grid to the data provider
Set dgrid.DataSource = adoPrimaryRS
dgrid.Visible = True
Exit Sub
Else
cmdList.Caption = "List"
cmdList.ToolTipText = "Show List"
'resize the window
Me.Height = Me.Height - dgrid.Height - 150
Set dgrid.DataSource = Nothing
dgrid.Visible = False
End If
End Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer)


'suppress any error messages
Response = 0
dgrid.DataChanged = False
End Sub

Private Sub Form_Load()


49
'set the connection to the main connection
Set db = studentsCon
'create a new recordset object
Set adoPrimaryRS = New ADODB.Recordset
'get data from the course table
adoPrimaryRS.Open "select CourseID,CourseName from Course Order by CourseID", db,
adOpenStatic, adLockOptimistic

mbDataChanged = False

Call InitializeControls
End Sub

Private Sub Form_Unload(Cancel As Integer)


Screen.MousePointer = vbDefault
Set db = Nothing
frmMain.SetFocus
End Sub

'The MoveComplete method is called after


'the current position in the Recordset changes.
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
On Error Resume Next
'This will display the current record position for this recordset
lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
End Sub

'The WillChangeRecord method is called


'before one or more records (rows) in the
'Recordset change.
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As
ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason


Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
50
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel


End Sub

'procedure for adding a new record


Private Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
'bookmark the current location
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
'add a new record
.AddNew
'change the status caption
lblStatus.Caption = "Add record"
'set the add new flag to true
mbAddNewFlag = True
'show/hide the buttons
SetButtons False
'unlock the textfields so that the user
'can write in the text fields
SetControls False
End With
Exit Sub
'error handling code
AddErr:
MsgBox Err.Description
End Sub

'procedure for deleting a record


Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
Dim chkVal As Variant
If chkDel.Value = Checked Then
chkVal = MsgBox("Delete the current record.", vbQuestion + vbYesNo, "Please Confirm")
If chkVal = vbNo Then Exit Sub
End If
51
With adoPrimaryRS
'delete the current record
.Delete
'ove to the next record
.MoveNext
'if eof is true then move to
' the last record
If .EOF Then .MoveLast
End With
Exit Sub
'eror handling code
DeleteErr:
MsgBox Err.Description
End Sub

'edit a record in the recordset


Private Sub cmdEdit_Click()
On Error GoTo EditErr
'set the status text
lblStatus.Caption = "Edit record"

With adoPrimaryRS
If Not (.BOF And .EOF) Then
'bookmark the current record location
mvBookMark = .Bookmark
End If
End With

'set edit flag to true


mbEditFlag = True
'show/hide buttons
SetButtons False
'unlock the text boxes for editing
SetControls False
Exit Sub
'error handling code
EditErr:
MsgBox Err.Description
End Sub

'cancel any updates made


Private Sub cmdCancel_Click()
On Error Resume Next
'show/hide buttons
SetButtons True
52
'lock the text fields
SetControls True
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'Cancel any changes made to the current
'record or to a new record prior to
'calling the Update method.
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
'move to previous bookmark
adoPrimaryRS.Bookmark = mvBookMark
Else
'if there is no bookmark
'then move to the first record
adoPrimaryRS.MoveFirst
End If
'set the data changed flag to false
mbDataChanged = False

End Sub

'update any changes made by the user


'to the database
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'writes new records to disk
adoPrimaryRS.UpdateBatch adAffectAll
'check if add flag is true
If mbAddNewFlag Then
adoPrimaryRS.MoveLast
End If
'check if edit flag is true
If mbEditFlag Then
lblStatus.Caption = "Record: " & adoPrimaryRS.AbsolutePosition
End If
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'show/hide buttons
SetButtons True
'lock the text fields because the
'user has updates the record
53
SetControls True
'set data changed to false
mbDataChanged = False
Exit Sub
'error handling code
UpdateErr:
MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()


Unload Me
End Sub

'procedure to move to the first record


Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
'move to the first record in the
'recorset
adoPrimaryRS.MoveFirst
mbDataChanged = False

Exit Sub
'error handling code
GoFirstError:
MsgBox Err.Description
End Sub

'procedure to move to the last record


Private Sub cmdLast_Click()
On Error GoTo GoLastError
'move to the last record
adoPrimaryRS.MoveLast
mbDataChanged = False

Exit Sub
'error handling code
GoLastError:
MsgBox Err.Description
End Sub

'procedure to move to the next record


Private Sub cmdNext_Click()
On Error GoTo GoNextError
'if not EOF(end of file)then
'move to the last record
54
If Not adoPrimaryRS.EOF Then
adoPrimaryRS.MoveNext
End If

If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then


Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False

Exit Sub
GoNextError:
MsgBox Err.Description
End Sub

'procedure to move to the previous record


Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError

If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious


If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False

Exit Sub
'error handling code
GoPrevError:
MsgBox Err.Description
End Sub

'this procedure is used for showing/hiding


'buttons when the user clicks the add, edit,
'update, cancel buttons. It also
'enables/disables the navigation buttons
Private Sub SetButtons(bVal As Boolean)
'show/hide buttons
cmdAdd.Visible = bVal
cmdEdit.Visible = bVal
cmdUpdate.Visible = Not bVal
55
cmdCancel.Visible = Not bVal
cmdDelete.Visible = bVal
cmdClose.Visible = bVal

'enable/disable buttons
cmdNext.Enabled = bVal
cmdFirst.Enabled = bVal
cmdLast.Enabled = bVal
cmdPrevious.Enabled = bVal
End Sub

'this procedure unlocks the textfields


'when the user presses the add or edit button.
'It locks the text fields when the user
'presses the update or cancel button.
Private Sub SetControls(bVal As Boolean)
Dim oText As TextBox
For Each oText In Me.txtFields
oText.Locked = bVal
Next
End Sub

'this procedure is used to initialize various


'controls on the form like textfields,
'data grid, etc.
Private Sub InitializeControls()
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
oText.Locked = True
Next
'set the appearance to flat
txtFields(0).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(0).DataField = "CourseID"
'set the appearance to flat
txtFields(1).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(1).DataField = "CourseName"

'make the font bold


lblLabels(0).FontBold = True
56
lblLabels(1).FontBold = True

'set default value to checked


chkDel.Value = vbChecked

''''Data Grid settings

'don't allow the user to add new records


'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
dgrid.AllowUpdate = False
'set column 0 caption
dgrid.Columns(0).Caption = "Course ID"
'bind the column to a datafield
dgrid.Columns(0).DataField = "CourseID"
dgrid.Columns(1).Caption = "Course Name"
dgrid.Columns(1).DataField = "CourseName"
'set the width of columns
dgrid.Columns(0).Width = 900
dgrid.Columns(1).Width = 2550

'set the height of the form


Me.Height = 2400
End Sub

57
The Subject Screen - frmSubject

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim WithEvents adoPrimaryRS As ADODB.Recordset
'variable to bookmark current location
Dim mvBookMark As Variant
'variable for editing
Dim mbEditFlag As Boolean
'variable for adding new records
Dim mbAddNewFlag As Boolean
'flag for data changes
Dim mbDataChanged As Boolean

'show/hide all records grid


Private Sub cmdList_Click()
'shows all the records in a grid
If cmdList.Caption = "List" Then
cmdList.Caption = "Hide"
cmdList.ToolTipText = "Hide List"
'resize the window
Me.Height = Me.Height + dgrid.Height + 180
'Bind the data grid to the data provider
Set dgrid.DataSource = adoPrimaryRS
dgrid.Visible = True
Exit Sub
Else
cmdList.Caption = "List"
cmdList.ToolTipText = "Show List"
'resize the window
Me.Height = Me.Height - dgrid.Height - 180
Set dgrid.DataSource = Nothing
dgrid.Visible = False
End If
End Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer)


'suppress any error messages
Response = 0
dgrid.DataChanged = False
End Sub

Private Sub Form_Load()


58
'set the connection to the main connection
Set db = studentsCon
'create a new recordset object
Set adoPrimaryRS = New ADODB.Recordset
'get data from subjects table
adoPrimaryRS.Open "select SubjectID,SubjectName,CourseID,TeacherID from Subject Order
by CourseID,subjectid", db, adOpenStatic, adLockOptimistic

mbDataChanged = False
'procedure to initialize all the controls
Call InitializeControls
End Sub

Private Sub Form_Unload(Cancel As Integer)


Screen.MousePointer = vbDefault
Set db = Nothing
'set focus on the main window
frmMain.SetFocus
End Sub
'The MoveComplete method is called after
'the current position in the Recordset changes.
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
On Error Resume Next
'This will display the current record position for this recordset
lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
End Sub

'The WillChangeRecord method is called


'before one or more records (rows) in the
'Recordset change.
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As
ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason


Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
59
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel


End Sub

'procedure for adding a new record


Private Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
'bookmark the current location
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
'add a new record
.AddNew
'change the status caption
lblStatus.Caption = "Add record"
'set the add new flag to true
mbAddNewFlag = True
'show/hide the buttons
SetButtons False
'unlock the textfields so that the user
'can write in the text fields
SetControls False
End With
Exit Sub
'error handling code
AddErr:
MsgBox Err.Description
End Sub

'procedure for deleting a record


Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
Dim chkVal As Variant
If chkDel.Value = Checked Then
chkVal = MsgBox("Delete the current record.", vbQuestion + vbYesNo, "Please Confirm")
If chkVal = vbNo Then Exit Sub
End If
60
With adoPrimaryRS
'delete the current record
.Delete
'ove to the next record
.MoveNext
'if eof is true then move to
' the last record
If .EOF Then .MoveLast
End With
Exit Sub
'eror handling code
DeleteErr:
MsgBox Err.Description
End Sub

'edit a record in the recordset


Private Sub cmdEdit_Click()
On Error GoTo EditErr
'set the status text
lblStatus.Caption = "Edit record"

With adoPrimaryRS
If Not (.BOF And .EOF) Then
'bookmark the current record location
mvBookMark = .Bookmark
End If
End With

'set edit flag to true


mbEditFlag = True
'show/hide buttons
SetButtons False
'unlock the text boxes for editing
SetControls False
Exit Sub
'error handling code
EditErr:
MsgBox Err.Description
End Sub

'cancel any updates made


Private Sub cmdCancel_Click()
On Error Resume Next
'show/hide buttons
SetButtons True
61
'lock the text fields
SetControls True
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'Cancel any changes made to the current
'record or to a new record prior to
'calling the Update method.
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
'move to previous bookmark
adoPrimaryRS.Bookmark = mvBookMark
Else
'if there is no bookmark
'then move to the first record
adoPrimaryRS.MoveFirst
End If
'set the data changed flag to false
mbDataChanged = False

End Sub

'update any changes made by the user


'to the database
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'writes new records to disk
adoPrimaryRS.UpdateBatch adAffectAll
'check if add flag is true
If mbAddNewFlag Then
adoPrimaryRS.MoveLast
End If
'check if edit flag is true
If mbEditFlag Then
lblStatus.Caption = "Record: " & adoPrimaryRS.AbsolutePosition
End If
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'show/hide buttons
SetButtons True
'lock the text fields because the
'user has updates the record
62
SetControls True
'set data changed to false
mbDataChanged = False
Exit Sub
'error handling code
UpdateErr:
MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()


Unload Me
End Sub

'procedure to move to the first record


Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
'move to the first record in the
'recorset
adoPrimaryRS.MoveFirst
mbDataChanged = False

Exit Sub
'error handling code
GoFirstError:
MsgBox Err.Description
End Sub

'procedure to move to the last record


Private Sub cmdLast_Click()
On Error GoTo GoLastError
'move to the last record
adoPrimaryRS.MoveLast
mbDataChanged = False

Exit Sub
'error handling code
GoLastError:
MsgBox Err.Description
End Sub

'procedure to move to the next record


Private Sub cmdNext_Click()
On Error GoTo GoNextError
'if not EOF(end of file)then
'move to the last record
63
If Not adoPrimaryRS.EOF Then
adoPrimaryRS.MoveNext
End If

If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then


Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False

Exit Sub
GoNextError:
MsgBox Err.Description
End Sub

'procedure to move to the previous record


Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError

If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious


If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False

Exit Sub
'error handling code
GoPrevError:
MsgBox Err.Description
End Sub

'this procedure is used for showing/hiding


'buttons when the user clicks the add, edit,
'update, cancel buttons. It also
'enables/disables the navigation buttons
Private Sub SetButtons(bVal As Boolean)
'show/hide buttons
cmdAdd.Visible = bVal
cmdEdit.Visible = bVal
cmdUpdate.Visible = Not bVal
64
cmdCancel.Visible = Not bVal
cmdDelete.Visible = bVal
cmdClose.Visible = bVal

'enable/disable buttons
cmdNext.Enabled = bVal
cmdFirst.Enabled = bVal
cmdLast.Enabled = bVal
cmdPrevious.Enabled = bVal
End Sub

'this procedure unlocks the fields


'when the user presses the add or edit button.
'It locks the fields when the user
'presses the update or cancel button.
Private Sub SetControls(bVal As Boolean)
Dim oText As TextBox
For Each oText In Me.txtFields
oText.Locked = bVal
Next
cboCourse.Locked = bVal
cboTeacher.Locked = bVal
End Sub

'this procedure is used to initialize various


'controls on the form like textfields,
'data grid, etc.
Private Sub InitializeControls()
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
oText.Locked = True
Next
'set the appearance to flat
txtFields(0).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(0).DataField = "SubjectID"
txtFields(0).FontBold = True
'set the appearance to flat
txtFields(1).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(1).DataField = "SubjectName"
65
'make the font bold
lblLabels(0).FontBold = True
lblLabels(1).FontBold = True
lblLabels(2).FontBold = True
lblLabels(3).FontBold = True

'set default value to checked


chkDel.Value = vbChecked

''''Data Grid settings


'Set dgrid.DataSource = adoPrimaryRS
'don't allow the user to add new records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
dgrid.AllowUpdate = False
dgrid.Columns.Add 2
'set column 0 caption
dgrid.Columns(0).Caption = "Subject ID"
'bind the column to a datafield
dgrid.Columns(0).DataField = "SubjectID"
dgrid.Columns(1).Caption = "Subject Name"
dgrid.Columns(1).DataField = "SubjectName"
dgrid.Columns(2).Caption = "Course ID"
dgrid.Columns(2).DataField = "CourseID"

'set the width of columns


dgrid.Columns(0).Width = 850
dgrid.Columns(1).Width = 2450
dgrid.Columns(2).Width = 800

'set the height of the form


Me.Height = 3210

'combo box settings


Dim rsTemp As ADODB.Recordset
Set rsTemp = New Recordset
66
rsTemp.Open "select CourseID from Course Order by CourseID", db, adOpenStatic,
adLockOptimistic

'add courses to the combo box


While rsTemp.EOF <> True
cboCourse.AddItem rsTemp.Fields(0)
rsTemp.MoveNext
Wend
'close the recordset
rsTemp.Close
'set the datasource of course combo box
Set cboCourse.DataSource = adoPrimaryRS

rsTemp.Open "select TeacherID from Teacher Order by TeacherID", db, adOpenStatic,


adLockOptimistic

'add teachers ID to the combo boxes


While rsTemp.EOF <> True
cboTeacher.AddItem rsTemp.Fields(0)
rsTemp.MoveNext
Wend
'close the recordset
rsTemp.Close
'set the datasource of teacher combo box
Set cboTeacher.DataSource = adoPrimaryRS
End Sub

67
The Teacher Screen – frmTeacher

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim WithEvents adoPrimaryRS As ADODB.Recordset
'variable to bookmark current location
Dim mvBookMark As Variant
'variable for editing
Dim mbEditFlag As Boolean
'variable for adding new records
Dim mbAddNewFlag As Boolean
'flag for data changes
Dim mbDataChanged As Boolean

'show/hide all records grid


Private Sub cmdList_Click()
'shows all the records in a grid
If cmdList.Caption = "List" Then
cmdList.Caption = "Hide"
cmdList.ToolTipText = "Hide List"
'resize the window
Me.Width = Me.Width + dgrid.Width + 150
Set dgrid.DataSource = adoPrimaryRS
dgrid.Visible = True
Exit Sub
Else
cmdList.Caption = "List"
cmdList.ToolTipText = "Show List"
'resize the window
Me.Width = Me.Width - dgrid.Width - 150
Set dgrid.DataSource = Nothing
dgrid.Visible = False
End If
End Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer)


'suppress any error messages
Response = 0
dgrid.DataChanged = False
End Sub

Private Sub Form_Load()


'set the connection
68
Set db = studentsCon
'create new recordset
Set adoPrimaryRS = New ADODB.Recordset
'get records from the teacher table
adoPrimaryRS.Open "select TeacherID,Name,Address,City,State,PhoneNumber from Teacher
Order by TeacherID", db, adOpenStatic, adLockOptimistic

mbDataChanged = False
Call InitializeControls
End Sub

Private Sub Form_Unload(Cancel As Integer)


Screen.MousePointer = vbDefault
Set db = Nothing
frmMain.SetFocus
End Sub
'The MoveComplete method is called after
'the current position in the Recordset changes.
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
On Error Resume Next
'This will display the current record position for this recordset
lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
End Sub

'The WillChangeRecord method is called


'before one or more records (rows) in the
'Recordset change.
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As
ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason


Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
69
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel


End Sub

'procedure for adding a new record


Private Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
'bookmark the current location
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
'add a new record
.AddNew
'change the status caption
lblStatus.Caption = "Add record"
'set the add new flag to true
mbAddNewFlag = True
'show/hide the buttons
SetButtons False
'unlock the textfields so that the user
'can write in the text fields
SetControls False
End With
Exit Sub
'error handling code
AddErr:
MsgBox Err.Description
End Sub

'procedure for deleting a record


Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
Dim chkVal As Variant
If chkDel.Value = Checked Then
chkVal = MsgBox("Delete the current record.", vbQuestion + vbYesNo, "Please Confirm")
If chkVal = vbNo Then Exit Sub
End If
With adoPrimaryRS
'delete the current record
.Delete
70
'ove to the next record
.MoveNext
'if eof is true then move to
' the last record
If .EOF Then .MoveLast
End With
Exit Sub
'eror handling code
DeleteErr:
MsgBox Err.Description
End Sub

'edit a record in the recordset


Private Sub cmdEdit_Click()
On Error GoTo EditErr
'set the status text
lblStatus.Caption = "Edit record"

With adoPrimaryRS
If Not (.BOF And .EOF) Then
'bookmark the current record location
mvBookMark = .Bookmark
End If
End With

'set edit flag to true


mbEditFlag = True
'show/hide buttons
SetButtons False
'unlock the text boxes for editing
SetControls False
Exit Sub
'error handling code
EditErr:
MsgBox Err.Description
End Sub

'cancel any updates made


Private Sub cmdCancel_Click()
On Error Resume Next
'show/hide buttons
SetButtons True
'lock the text fields
SetControls True
'set the edit flag to false
71
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'Cancel any changes made to the current
'record or to a new record prior to
'calling the Update method.
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
'move to previous bookmark
adoPrimaryRS.Bookmark = mvBookMark
Else
'if there is no bookmark
'then move to the first record
adoPrimaryRS.MoveFirst
End If
'set the data changed flag to false
mbDataChanged = False

End Sub

'update any changes made by the user


'to the database
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'writes new records to disk
adoPrimaryRS.UpdateBatch adAffectAll
'check if add flag is true
If mbAddNewFlag Then
adoPrimaryRS.MoveLast
End If
'check if edit flag is true
If mbEditFlag Then
lblStatus.Caption = "Record: " & adoPrimaryRS.AbsolutePosition
End If
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'show/hide buttons
SetButtons True
'lock the text fields because the
'user has updates the record
SetControls True
'set data changed to false
mbDataChanged = False
72
Exit Sub
'error handling code
UpdateErr:
MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()


Unload Me
End Sub
'procedure to move to the first record
Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
'move to the first record in the
'recorset
adoPrimaryRS.MoveFirst
mbDataChanged = False

Exit Sub
'error handling code
GoFirstError:
MsgBox Err.Description
End Sub

'procedure to move to the last record


Private Sub cmdLast_Click()
On Error GoTo GoLastError
'move to the last record
adoPrimaryRS.MoveLast
mbDataChanged = False

Exit Sub
'error handling code
GoLastError:
MsgBox Err.Description
End Sub

'procedure to move to the next record


Private Sub cmdNext_Click()
On Error GoTo GoNextError
'if not EOF(end of file)then
'move to the last record
If Not adoPrimaryRS.EOF Then
adoPrimaryRS.MoveNext
End If

73
If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False

Exit Sub
GoNextError:
MsgBox Err.Description
End Sub

'procedure to move to the previous record


Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError

If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious


If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False

Exit Sub
'error handling code
GoPrevError:
MsgBox Err.Description
End Sub

'this procedure is used for showing/hiding


'buttons when the user clicks the add, edit,
'update, cancel buttons. It also
'enables/disables the navigation buttons
Private Sub SetButtons(bVal As Boolean)
'show/hide buttons
cmdAdd.Visible = bVal
cmdEdit.Visible = bVal
cmdUpdate.Visible = Not bVal
cmdCancel.Visible = Not bVal
cmdDelete.Visible = bVal
cmdClose.Visible = bVal

74
'enable/disable buttons
cmdNext.Enabled = bVal
cmdFirst.Enabled = bVal
cmdLast.Enabled = bVal
cmdPrevious.Enabled = bVal
End Sub

'this procedure unlocks the textfields


'when the user presses the add or edit button.
'It locks the text fields when the user
'presses the update or cancel button.
Private Sub SetControls(bVal As Boolean)
Dim oText As TextBox
For Each oText In Me.txtFields
oText.Locked = bVal
Next
End Sub

'this procedure is used to initialize various


'controls on the form like textfields,
'data grid, etc.
Private Sub InitializeControls()
Dim oText As TextBox
For Each oText In Me.txtFields
'Bind the text boxes to the data provider
Set oText.DataSource = adoPrimaryRS
'set the appearance to flat
oText.Appearance = 0
'lock the controls
oText.Locked = True
Next

'set the name of a field that the


'textfield will be bound to.
txtFields(0).DataField = "TeacherID"
txtFields(1).DataField = "Name"
txtFields(2).DataField = "Address"
txtFields(3).DataField = "City"
txtFields(4).DataField = "State"
txtFields(5).DataField = "PhoneNumber"

'set default value to checked


chkDel.Value = vbChecked

''''Data Grid settings


75
'don't allow the user to add new records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
dgrid.AllowUpdate = False
'set column 0 caption
dgrid.Columns(0).Caption = "Teacher ID"
'bind the column to a datafield
dgrid.Columns(0).DataField = "TeacherID"
dgrid.Columns(1).Caption = "Teacher Name"
dgrid.Columns(1).DataField = "Name"
'set the width of columns
dgrid.Columns(0).Width = 950
dgrid.Columns(1).Width = 1500

'set the form width


Me.Width = 4380
End Sub

76
The Result All Screen- frmResult

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim WithEvents adoPrimaryRS As ADODB.Recordset
'variable to bookmark current location
Dim mvBookMark As Variant
'variable for editing
Dim mbEditFlag As Boolean
'variable for adding new records
Dim mbAddNewFlag As Boolean
'flag for data changes
Dim mbDataChanged As Boolean

'show/hide all records grid


Private Sub cmdList_Click()
'shows all the records in a grid
If cmdList.Caption = "List" Then
cmdList.Caption = "Hide"
cmdList.ToolTipText = "Hide List"
'resize the window
Me.Height = Me.Height + dgrid.Height + 150
'Bind the data grid to the data provider
Set dgrid.DataSource = adoPrimaryRS
dgrid.Visible = True
Exit Sub
Else
cmdList.Caption = "List"
cmdList.ToolTipText = "Show List"
'resize the window
Me.Height = Me.Height - dgrid.Height - 150
Set dgrid.DataSource = Nothing
dgrid.Visible = False
End If
End Sub

Private Sub Form_Load()

'set the connection to the main connection


Set db = studentsCon
'create a new recordset object
Set adoPrimaryRS = New ADODB.Recordset
'get data from the result table
77
adoPrimaryRS.Open "select RollNo,SubjectID,Marks,Status from Result Order by RollNo", db,
adOpenStatic, adLockOptimistic

mbDataChanged = False
'procedure to initialize controls on the form
Call InitializeControls
End Sub

'this procedure is called when the form is


'unloaded from the memory
Private Sub Form_Unload(Cancel As Integer)
Screen.MousePointer = vbDefault
Set db = Nothing
'set focus on the main window
frmMain.SetFocus
End Sub

'The MoveComplete method is called after


'the current position in the Recordset changes.
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
On Error Resume Next
'This will display the current record position for this recordset
lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
End Sub

'The WillChangeRecord method is called


'before one or more records (rows) in the
'Recordset change.
Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As
ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason


Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
Case adRsnRequery
Case adRsnResynch
78
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel


End Sub

'procedure for adding a new record


Private Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
'bookmark the current location
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
'add a new record
.AddNew
'change the status caption
lblStatus.Caption = "Add record"
'set the add new flag to true
mbAddNewFlag = True
'show/hide the buttons
SetButtons False
'unlock the textfields so that the user
'can write in the text fields
SetControls False
End With
Exit Sub
'error handling code
AddErr:
MsgBox Err.Description
End Sub

'procedure for deleting a record


Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
Dim chkVal As Variant
If chkDel.Value = Checked Then
chkVal = MsgBox("Delete the current record.", vbQuestion + vbYesNo, "Please Confirm")
If chkVal = vbNo Then Exit Sub
End If
With adoPrimaryRS
'delete the current record
79
.Delete
'ove to the next record
.MoveNext
'if eof is true then move to
' the last record
If .EOF Then .MoveLast
End With
Exit Sub
'eror handling code
DeleteErr:
MsgBox Err.Description
End Sub

'edit a record in the recordset


Private Sub cmdEdit_Click()
On Error GoTo EditErr
'set the status text
lblStatus.Caption = "Edit record"

With adoPrimaryRS
If Not (.BOF And .EOF) Then
'bookmark the current record location
mvBookMark = .Bookmark
End If
End With

'set edit flag to true


mbEditFlag = True
'show/hide buttons
SetButtons False
'unlock the text boxes for editing
SetControls False
Exit Sub
'error handling code
EditErr:
MsgBox Err.Description
End Sub

'cancel any updates made


Private Sub cmdCancel_Click()
On Error Resume Next
'show/hide buttons
SetButtons True
'lock the text fields
SetControls True
80
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'Cancel any changes made to the current
'record or to a new record prior to
'calling the Update method.
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
'move to previous bookmark
adoPrimaryRS.Bookmark = mvBookMark
Else
'if there is no bookmark
'then move to the first record
adoPrimaryRS.MoveFirst
End If
'set the data changed flag to false
mbDataChanged = False

End Sub

'update any changes made by the user


'to the database
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'writes new records to disk
adoPrimaryRS.UpdateBatch adAffectAll
'check if add flag is true
If mbAddNewFlag Then
adoPrimaryRS.MoveLast
End If
'check if edit flag is true
If mbEditFlag Then
lblStatus.Caption = "Record: " & adoPrimaryRS.AbsolutePosition
End If
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'show/hide buttons
SetButtons True
'lock the text fields because the
'user has updates the record
SetControls True
'set data changed to false
81
mbDataChanged = False
Exit Sub
'error handling code
UpdateErr:
MsgBox Err.Description
End Sub
'procedure to close the result form
Private Sub cmdClose_Click()
Unload Me
End Sub

'procedure to move to the first record


Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
'move to the first record in the
'recorset
adoPrimaryRS.MoveFirst
mbDataChanged = False

Exit Sub
'error handling code
GoFirstError:
MsgBox Err.Description
End Sub

'procedure to move to the last record


Private Sub cmdLast_Click()
On Error GoTo GoLastError
'move to the last record
adoPrimaryRS.MoveLast
mbDataChanged = False

Exit Sub
'error handling code
GoLastError:
MsgBox Err.Description
End Sub

'procedure to move to the next record


Private Sub cmdNext_Click()
On Error GoTo GoNextError
'if not EOF(end of file)then
'move to the last record
If Not adoPrimaryRS.EOF Then
adoPrimaryRS.MoveNext
82
End If

If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then


Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False

Exit Sub
GoNextError:
MsgBox Err.Description
End Sub

'procedure to move to the previous record


Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError

If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious


If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False

Exit Sub
'error handling code
GoPrevError:
MsgBox Err.Description
End Sub

'this procedure is used for showing/hiding


'buttons when the user clicks the add, edit,
'update, cancel buttons. It also
'enables/disables the navigation buttons
Private Sub SetButtons(bVal As Boolean)
'show/hide buttons
cmdAdd.Visible = bVal
cmdEdit.Visible = bVal
cmdUpdate.Visible = Not bVal
cmdCancel.Visible = Not bVal
cmdDelete.Visible = bVal
83
cmdClose.Visible = bVal

'enable/disable buttons
cmdNext.Enabled = bVal
cmdFirst.Enabled = bVal
cmdLast.Enabled = bVal
cmdPrevious.Enabled = bVal
End Sub

'this procedure unlocks the textfields


'when the user presses the add or edit button.
'It locks the text fields when the user
'presses the update or cancel button.
Private Sub SetControls(bVal As Boolean)
Dim oText As TextBox
For Each oText In Me.txtFields
oText.Locked = bVal
Next
End Sub

'this procedure is used to initialize various


'controls on the form like textfields,
'data grid, etc.
Private Sub InitializeControls()
Dim oText As TextBox
'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
oText.Locked = True
Next
'set the appearance to flat
txtFields(0).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(0).DataField = "RollNo"
'set the appearance to flat
txtFields(1).Appearance = 0
'set the name of a field that the
'textfield will be bound to.
txtFields(1).DataField = "SubjectID"
txtFields(2).Appearance = 0
txtFields(2).DataField = "Marks"
txtFields(3).Appearance = 0
txtFields(3).DataField = "Status"

84
'make the font bold
lblLabels(0).FontBold = True
lblLabels(1).FontBold = True
lblLabels(2).FontBold = True
lblLabels(3).FontBold = True

'set default value to checked


chkDel.Value = vbChecked
Call InitializeGrid

'set the height of the form


Me.Height = 2910

End Sub

Private Sub InitializeGrid()


''''Data Grid settings

'don't allow the user to add new records


'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
dgrid.AllowUpdate = False

'set column 0 caption


dgrid.Columns(0).Caption = "Roll No"
'bind the column to a datafield
dgrid.Columns(0).DataField = "RollNo"
dgrid.Columns(1).Caption = "Subject ID"
dgrid.Columns(1).DataField = "SubjectID"
'add a new column
dgrid.Columns.Add 2
dgrid.Columns(2).Caption = "Marks"
dgrid.Columns(2).DataField = "Marks"
'add a new column
dgrid.Columns.Add 3
dgrid.Columns(3).Caption = "Status"
dgrid.Columns(3).DataField = "Status"
85
'set the width of columns
dgrid.Columns(0).Width = 1000
dgrid.Columns(1).Width = 900
dgrid.Columns(2).Width = 800
dgrid.Columns(3).Width = 800
End Sub
'when any error occurs in the grid
Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer)
'suppress any error messages
Response = 0
'set the data changed to false
dgrid.DataChanged = False
End Sub

Private Sub txtFields_KeyPress(Index As Integer, KeyAscii As Integer)


If Index = 2 Then
'if back space is pressed then exit
If KeyAscii = 8 Then Exit Sub
If KeyAscii < 48 Or KeyAscii > 57 Then
'if the user tries to enter a string
'in the marks field then don't
'allow him.
KeyAscii = 0
End If
End If
End Sub

'this procedure is called when the


' focus is lost
Private Sub txtFields_LostFocus(Index As Integer)
'check if the user is adding a new record
If Trim(txtFields(2).Text) = "" Then Exit Sub
If Index = 2 Then
Dim intMarks As Integer
intMarks = txtFields(2).Text
'set the field according to marks entered
'SC - Successfully compelted, NC - Not Completed
If intMarks >= 50 Then txtFields(3).Text = "SC"
If intMarks < 50 Then txtFields(3).Text = "NC"
End If
End Sub

86
The Result by Roll No Screen - frmgetResult

'connection object
Dim db As ADODB.Connection

Private Sub cmdResult_Click()


On Error GoTo errCheck
'variable for roll number
Dim tempRoll As Long
'variable for marks
Dim tempMarks As Integer
'the record counter
Dim cnt As Integer
'student percentage
Dim percent As Single
'chack for blank field
If Trim(txtRollNo.Text) = "" Then Exit Sub
'convert the text in the txtbox to long
tempRoll = CLng(txtRollNo.Text)
'recordset variable
Dim rsTemp As ADODB.Recordset
'query variable
Dim strQry As String
'new recordset object
Set rsTemp = New ADODB.Recordset
'create a query
strQry = "select * from Result where RollNo=" & tempRoll
'get data from table
rsTemp.Open strQry, db, adOpenStatic, adLockOptimistic
'set the data grid source
Set dgrid.DataSource = rsTemp
'initial marks
tempMarks = 0
While rsTemp.EOF <> True
'calcculate the total of marks
tempMarks = tempMarks + rsTemp.Fields(2)
'move to the next record
rsTemp.MoveNext
Wend
'again move to the first record
rsTemp.MoveFirst
'initialize the record counter
cnt = rsTemp.RecordCount
'calculate the percentage of a student
percent = (tempMarks * 100) / (cnt * 100)
87
lblPercent.Caption = percent & "%"
'set the grade of the student according to the percentage
If percent >= 50 And percent < 60 Then lblGrade.Caption = "C"
If percent >= 60 And percent < 75 Then lblGrade.Caption = "B"
If percent >= 75 Then lblGrade.Caption = "A"
'set the total marks of the students
lblScore.Caption = tempMarks & "/" & (cnt * 100)

rsTemp.ActiveConnection = Nothing

Exit Sub
errCheck:
If Err.Number = 13 Then MsgBox "Please Enter a valid roll number", , "Error"
End Sub

Private Sub Form_Load()


'set the connection to the main connection
Set db = studentsCon

'bind the column to a datafield


dgrid.Columns(0).Caption = "Subject ID"
dgrid.Columns(0).DataField = "SubjectID"
dgrid.Columns(1).Caption = "Marks"
dgrid.Columns(1).DataField = "Marks"
dgrid.Columns.Add 2
dgrid.Columns(2).Caption = "Status"
dgrid.Columns(2).DataField = "Status"
'set the width of columns
dgrid.Columns(0).Width = 900
dgrid.Columns(1).Width = 900
dgrid.Columns(2).Width = 700

Label1.FontBold = True
Label2.FontBold = True
Label3.FontBold = True
Label4.FontBold = True
txtRollNo.Appearance = 0
End Sub

'this procedure is called when the


'form is unloaded from memory
Private Sub Form_Unload(Cancel As Integer)
'se the connection to nothing
Set db = Nothing
'set the focus on the main window
88
frmMain.SetFocus
End Sub

89
The Student Screen – frmStudent

'variable declaration
'connection object
Dim db As ADODB.Connection
'recordset object
Dim WithEvents adoPrimaryRS As ADODB.Recordset
'variable to bookmark current location
Dim mvBookMark As Variant
'variable for editing
Dim mbEditFlag As Boolean
'variable for adding new records
Dim mbAddNewFlag As Boolean
'flag for data changes
Dim mbDataChanged As Boolean

'show/hide all records grid


Public Sub cmdList_Click()
'shows all the records in a grid
If cmdList.Caption = "List" Then
cmdList.Caption = "Hide"
cmdList.ToolTipText = "Hide List"
'resize the window
Me.Height = Me.Height + dgrid.Height + 150
'Bind the data grid to the data provider
Set dgrid.DataSource = adoPrimaryRS
dgrid.Visible = True
Exit Sub
Else
cmdList.Caption = "List"
cmdList.ToolTipText = "Show List"
'resize the window
Me.Height = Me.Height - dgrid.Height - 150
Set dgrid.DataSource = Nothing
dgrid.Visible = False
End If
End Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer)


'suppress any error messages
Response = 0
dgrid.DataChanged = False
End Sub

Private Sub Form_Load()


90
'set the connection to the main connection
Set db = studentsCon
'create a new recordset object
Set adoPrimaryRS = New ADODB.Recordset
'get the data from student table
adoPrimaryRS.Open "select
FirstName,LastName,RollNo,CourseID,DOB,FatherName,PhoneNumber,Email,Address,City,St
ate,PostalCode from Student Order by RollNo", db, adOpenStatic, adLockOptimistic

mbDataChanged = False
'call procedure to initialize the
'controls on the form
Call InitializeControls
End Sub

Private Sub Form_Unload(Cancel As Integer)


Screen.MousePointer = vbDefault
Set db = Nothing
'set focus on the main window
frmMain.SetFocus
End Sub

'The MoveComplete method is called after


'the current position in the Recordset changes.
Private Sub adoPrimaryRS_MoveComplete(ByVal adReason As ADODB.EventReasonEnum,
ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As
ADODB.Recordset)
On Error Resume Next
'This will display the current record position for this recordset
lblStatus.Caption = "Record: " & CStr(adoPrimaryRS.AbsolutePosition)
End Sub

Private Sub adoPrimaryRS_WillChangeRecord(ByVal adReason As


ADODB.EventReasonEnum, ByVal cRecords As Long, adStatus As ADODB.EventStatusEnum,
ByVal pRecordset As ADODB.Recordset)
'This is where you put validation code
'This event gets called when the following actions occur
Dim bCancel As Boolean

Select Case adReason


Case adRsnAddNew
Case adRsnClose
Case adRsnDelete
Case adRsnFirstChange
Case adRsnMove
91
Case adRsnRequery
Case adRsnResynch
Case adRsnUndoAddNew
Case adRsnUndoDelete
Case adRsnUndoUpdate
Case adRsnUpdate
End Select

If bCancel Then adStatus = adStatusCancel


End Sub

'procedure for adding a new record


Public Sub cmdAdd_Click()
On Error GoTo AddErr
With adoPrimaryRS
'bookmark the current location
If Not (.BOF And .EOF) Then
mvBookMark = .Bookmark
End If
'add a new record
.AddNew
'change the status caption
lblStatus.Caption = "Add record"
'set the add new flag to true
mbAddNewFlag = True
'show/hide the buttons
SetButtons False
'unlock the textfields so that the user
'can write in the text fields
SetControls False
End With
Exit Sub
'error handling code
AddErr:
MsgBox Err.Description
End Sub

'procedure for deleting a record


Private Sub cmdDelete_Click()
On Error GoTo DeleteErr
Dim chkVal As Variant
If chkDel.Value = Checked Then
chkVal = MsgBox("Delete the current record.", vbQuestion + vbYesNo, "Please Confirm")
If chkVal = vbNo Then Exit Sub
End If
92
With adoPrimaryRS
'delete the current record
.Delete
'ove to the next record
.MoveNext
'if eof is true then move to
' the last record
If .EOF Then .MoveLast
End With
Exit Sub
'eror handling code
DeleteErr:
MsgBox Err.Description
End Sub

'edit a record in the recordset


Public Sub cmdEdit_Click()
On Error GoTo EditErr
'set the status text
lblStatus.Caption = "Edit record"

With adoPrimaryRS
If Not (.BOF And .EOF) Then
'bookmark the current record location
mvBookMark = .Bookmark
End If
End With

'set edit flag to true


mbEditFlag = True
'show/hide buttons
SetButtons False
'unlock the text boxes for editing
SetControls False
Exit Sub
'error handling code
EditErr:
MsgBox Err.Description
End Sub

'cancel any updates made


Private Sub cmdCancel_Click()
On Error Resume Next
'show/hide buttons
SetButtons True
93
'lock the text fields
SetControls True
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'Cancel any changes made to the current
'record or to a new record prior to
'calling the Update method.
adoPrimaryRS.CancelUpdate
If mvBookMark > 0 Then
'move to previous bookmark
adoPrimaryRS.Bookmark = mvBookMark
Else
'if there is no bookmark
'then move to the first record
adoPrimaryRS.MoveFirst
End If
'set the data changed flag to false
mbDataChanged = False

End Sub

'update any changes made by the user


'to the database
Private Sub cmdUpdate_Click()
On Error GoTo UpdateErr
'writes new records to disk
adoPrimaryRS.UpdateBatch adAffectAll
'check if add flag is true
If mbAddNewFlag Then
adoPrimaryRS.MoveLast
End If
'check if edit flag is true
If mbEditFlag Then
lblStatus.Caption = "Record: " & adoPrimaryRS.AbsolutePosition
End If
'set the edit flag to false
mbEditFlag = False
'set the add flag to false
mbAddNewFlag = False
'show/hide buttons
SetButtons True
'lock the text fields because the
'user has updates the record
94
SetControls True
'set data changed to false
mbDataChanged = False
Exit Sub
'error handling code
UpdateErr:
MsgBox Err.Description
End Sub

Private Sub cmdClose_Click()


Unload Me
End Sub

'procedure to move to the first record


Private Sub cmdFirst_Click()
On Error GoTo GoFirstError
'move to the first record in the
'recorset
adoPrimaryRS.MoveFirst
mbDataChanged = False

Exit Sub
'error handling code
GoFirstError:
MsgBox Err.Description
End Sub

'procedure to move to the last record


Private Sub cmdLast_Click()
On Error GoTo GoLastError
'move to the last record
adoPrimaryRS.MoveLast
mbDataChanged = False

Exit Sub
'error handling code
GoLastError:
MsgBox Err.Description
End Sub

'procedure to move to the next record


Private Sub cmdNext_Click()
On Error GoTo GoNextError
'if not EOF(end of file)then
'move to the last record
95
If Not adoPrimaryRS.EOF Then
adoPrimaryRS.MoveNext
End If

If adoPrimaryRS.EOF And adoPrimaryRS.RecordCount > 0 Then


Beep
'moved off the end so go back
adoPrimaryRS.MoveLast
End If
'show the current record
mbDataChanged = False

Exit Sub
GoNextError:
MsgBox Err.Description
End Sub

'procedure to move to the previous record


Private Sub cmdPrevious_Click()
On Error GoTo GoPrevError

If Not adoPrimaryRS.BOF Then adoPrimaryRS.MovePrevious


If adoPrimaryRS.BOF And adoPrimaryRS.RecordCount > 0 Then
Beep
'moved off the end so go back
adoPrimaryRS.MoveFirst
End If
'show the current record
mbDataChanged = False

Exit Sub
'error handling code
GoPrevError:
MsgBox Err.Description
End Sub

'this procedure is used for showing/hiding


'buttons when the user clicks the add, edit,
'update, cancel buttons. It also
'enables/disables the navigation buttons
Private Sub SetButtons(bVal As Boolean)
'show/hide buttons
cmdAdd.Visible = bVal
cmdEdit.Visible = bVal
cmdUpdate.Visible = Not bVal
96
cmdCancel.Visible = Not bVal
cmdDelete.Visible = bVal
cmdClose.Visible = bVal

'enable/disable buttons
cmdNext.Enabled = bVal
cmdFirst.Enabled = bVal
cmdLast.Enabled = bVal
cmdPrevious.Enabled = bVal
End Sub

'this procedure unlocks the textfields


'when the user presses the add or edit button.
'It locks the text fields when the user
'presses the update or cancel button.
Private Sub SetControls(bVal As Boolean)
Dim oText As TextBox
For Each oText In Me.txtFields
oText.Locked = bVal
Next
cboCourse.Locked = False
End Sub

'this procedure is used to initialize various


'controls on the form like textfields,
'data grid, etc.
Private Sub InitializeControls()
Dim lbl As Label
For Each lbl In Me.lblLabels
lbl.FontBold = True
lbl.AutoSize = True
Next

Dim oText As TextBox


'Bind the text boxes to the data provider
For Each oText In Me.txtFields
Set oText.DataSource = adoPrimaryRS
'set the appearance of the text
'fields to flat
oText.Appearance = 0
'lock the controls
oText.Locked = True
Next

cboCourse.Locked = True
97
'set default value to checked
chkDel.Value = vbChecked

'set the height of the form


Me.Height = 4230

'combo box settings


Dim rsTemp As ADODB.Recordset
Set rsTemp = New Recordset
rsTemp.Open "select CourseID from Course Order by CourseID", db, adOpenStatic,
adLockOptimistic

'add courses to the combo box


While rsTemp.EOF <> True
cboCourse.AddItem rsTemp.Fields(0)
rsTemp.MoveNext
Wend
'close the recordset
rsTemp.Close
'set the datasource of course combo box
Set cboCourse.DataSource = adoPrimaryRS

Call InitializeGrid
End Sub

Private Sub InitializeGrid()


''''Data Grid settings

'don't allow the user to add new records


'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowAddNew = False
'don't allow the user to delete records
'to the Recordset object underlying a
'DataGrid control.
dgrid.AllowDelete = False
'don't allow the
'user to modify any data in the
'DataGrid control.
dgrid.AllowUpdate = False
'set column 0 caption
dgrid.Columns(0).Caption = "Roll No"
'bind the column to a datafield
dgrid.Columns(0).DataField = "RollNo"
dgrid.Columns(1).Caption = "First Name"
98
dgrid.Columns(1).DataField = "FirstName"
dgrid.Columns.Add 2
dgrid.Columns(2).Caption = "Last Name"
dgrid.Columns(2).DataField = "LastName"
dgrid.Columns.Add 3
dgrid.Columns(3).Caption = "Course"
dgrid.Columns(3).DataField = "CourseID"

'set the width of columns


dgrid.Columns(0).Width = 900
dgrid.Columns(1).Width = 1200
dgrid.Columns(2).Width = 1200
dgrid.Columns(3).Width = 1000
End Sub

Private Sub txtFields_LostFocus(Index As Integer)


'check the date of birth of student
If Index = 4 Then
If Trim(txtFields(4).Text) = "" Then Exit Sub
If IsDate(Trim(txtFields(4).Text)) = False Then
txtFields(4).Text = Date
MsgBox "Please enter a valid date."
txtFields(4).SetFocus
SendKeys ("{Home}+{End}")
End If
End If
End Sub

99
Code

Optimization

100
Code Optimization

The project student information management has been optimized to run fast. Moreover,

coding standards have been followed in this project to optimize the project for

maintainability.

The following Rules have been kept in mind for code optimization:

Remembering the 80/20 rule: In many fields you can get 80% of the result with 20% of

the effort When we optimized the code, we used profiling to find out where that 80% of

execution time is going.

Using the right algorithms and data structures: Don't use an O(n2) bubblesort

algorithm to sort a thousand elements when there's an O(n log n) quicksort available.

Similarly, don't store a thousand items in an array that requires an O(n) search when

you could use an O(log n) binary tree, or an O(1) Java hash table. We have used right

algorithms & data structures in the project.

101
Security Mechanism

Information such as intellectual property and strategic business data are stored,

processed, and disseminated by computers. Unauthorized access, revelation, or

destruction of data can violate individual privacy. Corruption of business data can result

in significant and potentially catastrophic losses to companies. In this project, a user

can't access the system until he or she has user ID and password. A new user is

created by the database administrator. Other users of the system have permission to

change their own passwords.

102
Validation Checks

Few checks and validations that are performed by the software are listed below:

 If the user is on the last record & he presses the next record button, the software

will remain on the current record (last record).

 Similarly, If the user is on the first record & he presses the previous record

button, the software will remain on the current record (first record).

 When the user tries to delete a record from the database, the software confirms

before deleting the record.

 While adding a new student record, the roll number field can't be left empty.

 While adding a new teacher, the teacher ID field can't be left blank.

 While adding a new course, the course ID field can't be left blank.

 While adding details in the subject list, the subject ID field can't be left blank.

 If the software is unable to connect to the database, it will not throw any error. It

will show a user-friendly message.

103
Software Testing

Techniques

104
Software Testing Techniques

Software testing is a critical element of software quality assurance and represents the

ultimate review of specification, design, and code generation. The increasing visibility of

software as a system element and the attendant costs associated with a software failure

are motivating forces for well planned, through testing.

The main objectives of testing are listed below:

 Testing is a process of executing a program with the intent of finding an error.

 A good test case is one that has a high probability of finding an as-yet-

undiscovered error.

 A successful test is one that uncovers an as-yet-undiscovered error.

Software is tested from two different perspectives: (1) internal program logic is

exercised using "white-box" test case design techniques.

(2) Software requirements are exercised using "black-box" test case design techniques.

In both cases, the intent is to find the maximum number of errors with the minimum

amount of effort and time.

Following are the two types of techniques, which have been used to test this project:

 White-box testing

 Black-box testing

105
White Box Testing

Techniques

106
Condition Testing

The condition testing method focuses on testing each condition in the program.

Condition testing is a test case design method that exercises the logical conditions

contained in a program module. A simple condition is a Boolean variable or a relational

expression, possibly preceded with one NOT (-) operator. A relational expression takes

the following form:

E1 < relational operator> E2

Where E1 and E2 are arithmetic expressions and <relational-operator> is one of the

following: <, ³ , =, ¹ , £ , >. A compound condition is composed of two or more simple

conditions, Boolean operators, and parentheses. A condition without relational

expressions is referred to as a Boolean expression. The possible types of elements in a

condition include a Boolean operator, a Boolean variable, a pair of Boolean

parentheses, a relational operator, or an arithmetic operator. If a condition is incorrect,

then at least one component of the condition is incorrect. Therefore, types of errors in a

condition include the following:

 Boolean operator error

 Boolean variable error

 Boolean parenthesis error

 Relational operator error

 Arithmetic expression error


107
The purpose of condition testing is to detect not only errors in the conditions of a

program but also other errors in the program. A number of condition testing strategies

have been proposed. Branch testing is the simplest condition testing strategy. For a

compound condition C, the true and false branches of C and every condition in C need

to be executed at least once. Domain testing requires three or four tests to be derived

for a relational expression. For a relational expression of the form.

E1 <relational operator> E2

Three tests are required to make the value of E 1 grater than, equal to, or less than that

of E2. If relational operator is incorrect and E1 and E2 are correct, then these three tests

guarantee the detection of the relational operator error.

For a Boolean expression with n variables, all of 2 n possible tests are required (n>0).

This strategy can detect Boolean operator, variable, and parenthesis errors, but it is

practical only if n is small. Error-sensitive tests for Boolean expressions can be derived.

For a singular Boolean expression, we can easily generate a test set with less than 2 n

tests such that this test set guarantees the detection of multiple boolean operator errors

and is also effective for detecting other errors.

For example, in this project, the following code segment checks if the last record is

reached then remain on the current record:

If Not adoPrimaryRS.EOF Then adoPrimaryRS.MoveNext

A technique called BRO (branch and relational operator) testing technique guarantees

the detection of branch and relational operator errors in a condition provided that all

108
Boolean variables and relational operators in the condition occur only once and have

common variables. The BRO strategy uses condition constraints for a condition C. A

condition constraint for C with n simple conditions is defined as (D 1, D2, …, Dn), where Di

(0 < i £ n) is a symbol specifying a constraint on the outcome of the ith simple condition

in condition C. A condition constraint D for condition C is said to be covered by an

execution of C if, during this execution of C, the outcome of each simple condition in C

satisfies the corresponding constraint in D.

For a Boolean variable, B, we specify a constraint on the outcome of that states that B

must be either true or false. Similarly, for a relational expression, the symbols >, =, < are

used to specify constraints on the outcome of the expression. Consider the following

example:

C 1 : B 1 & B2

Where B1 and B2 are Boolean variables. The condition constraint C1 is of the form (D1,

D2), where each D1 and D2 is t or f. The value (t, f) is a condition constraint for C1 and

is covered by the test that makes the value of B1 to be true and all the value of B2 false.

The BRO testing strategy requires that the constraint set {(t, t), (f, t), (t, f)} be covered by

the executions of C1. If C1 is incorrect due to one or more Boolean operator errors, at

least one of the constraint set will force C1 to fail.

109
Loop Testing

Loop testing is a white box testing technique that focuses exclusively on the validity of

loop constructs. Four different classes of loops can be defined:

 Simple loops

 Nested loops

 Concatenated loops

 Unstructured loops

110
Simple Loops

The following set of tests has been applied to simple loops, where n is the maximum

number of allowable passes through the loop.

1. Skip the loop entirely.

2. Only one pass through the loop.

3. Two passes through the loop.

4. m passes through the loop where m < n

5. n - 1, n, n + 1 passes through the loop.

111
Nested loops

If we were to extend the test approach for simple loops to nested loops, the number of

possible tests would grow geometrically as the level of nesting increases. The following

steps will help to reduce the number of tests:

1. Start at the innermost loop. Set all other loops to minimum values.

2. Conduct simple loop tests for the innermost loop while holding the outer loops at

their minimum iteration parameter (e.g., loop counter) values. Add other tests for

out of range or excluded values.

3. Work outward, conducting tests for the next loop, but keeping all the other outer

loops at minimum values and other nested loops to typical values.

4. Continue until all loops have been tested.

112
113
Concatenated loops

Concatenated loops have been tested using the approach defined for simple loops, if

each of the loops is independent of the other. However, if two loops are concatenated

the approach applied to nested loops is used.

114
Black Box

Testing

115
Graph Based Testing Methods

The first step is to understand the objects that are modeled in software and the

relationships that connect these objects. First a graph of important objects and their

relationships is created. A graph is a collection of nodes that represent objects; links

that represent the relationship between objects; node weights that describe the

properties of a node; and link weights that describe some characteristic of a link. The

following figure depicts the symbolic representation of a simple graph:

116
A directed link indicates that a relationship moves in only one direction. A bi-directional

link implies that the relationship applies in both directions. Parallel links are used when

a number of different relationships are established between graph nodes. There are

several behavioral testing methods that can make use of graphs.

 Transaction flow modeling

 Finite state modeling

 Data flow modeling

 Timing modeling

Graph based testing begins with the definition of all nodes and node weights. The data

model is used as a starting point. Once nodes have been identified, links and link

weights should be established. In many cases, the graph model may have loops. Loop

testing can be applied at the behavioral level. The graph assists in identifying loops that

need to be tested.

117
Boundary Value Analysis

There are several errors that occur at the boundaries of the input domain rather than in

the center. BVA leads to a selection of test cases that exercise bounding values. BVA

complements equivalence partitioning.

For example, in student project when the software reaches the last record & the user

presses the next record button, the software will not throw any exception. Similarly,

when the software is on the first record & the user presses the previous record button,

the software will remain on the first record.

118
Software Testing

Strategies

119
Unit Testing

It focuses on the smallest unit of software design - the software component or module.

Using the component level design description as a guide, important control paths are

tested to uncover errors within the boundary of the module. The relative complexity of

tests and uncovered errors is limited by the constrained scope established for unit

testing. The unit test is white-box oriented, and the step can be conducted in parallel for

multiple components. The tests that occur as part of unit tests are listed below:

 Module Interface is tested to ensure that information properly flows into and out

of the program unit under test. Tests of data flow across a module interface are

required before any other test is initiated. If data does not enter and exit properly,

all other tests are moot.

 Local Data Structures are examined to ensure that data stored temporarily

maintains its integrity during all steps in an algorithm's execution.

 Boundary Conditions are tested to ensure that the module operates properly at

boundaries established to limit or restrict processing.

 Independent Paths are exercised to ensure that all statements in a module have

been executed at least once.

 Error Handling Paths are also tested.

120
Selective testing of execution paths is an essential task during the unit test. Basis path

and loop testing are effective techniques for uncovering a broad array of path errors.

Among the more common errors in computation are

 misunderstood or incorrect arithmetic precedence,

 mixed mode operations

 incorrect initialization

 precision inaccuracy

 incorrect symbolic representation of an expression.

Among the potential errors that should be tested when error handling is evaluated

 Error description is unintelligible

 Error noted does not correspond to error encountered

 Error condition causes system intervention prior to error handling

 Exception-condition processing is incorrect

 Error description does not provide enough information to assist in the location of

the cause of the error.

121
Integration Testing

After the testing of each module separately, all of them are tested jointly to check how a

data flows from one module to another module. Because this data flow may give

uncovered errors that have not been covered in the unit testing. And so they are

checked with full compilation. The objective is to take unit tested components and build

a program structure that has been dictated by design. Integration testing is a systematic

technique for constructing the program structure while at the same time conducting

tests to uncover errors associated with interfacing.

122
Smoke Testing

It encompasses the following activities:

 Software components that have been translated into a build. A build includes all

data files, libraries, reusable modules, and engineered components that are

required to implement one or more product functions.

 A series of tests is designed to expose errors that will keep the build from

properly performing its functions. The intent should be to uncover "show stopper"

errors that have the highest likelihood of throwing the software project behind

schedule.

 The build is integrated with other builds and the entire product is smoke tested

daily.

Smoke testing provides a number of benefits when it is applied on complex, time-

critical software engineering projects.

123
Validation Testing

At the culmination of integration testing, software is completely assembled as a

package, interfacing errors have been uncovered and corrected, and a final series of

software tests-validation testing-may begin. Validation can be defined in many ways, but

a simple definition is that validation succeeds when software functions in a manner that

can be reasonably expected by the customer. Software validation is achieved through a

series of black box tests that demonstrate conformity with the requirements. A test plan

outlines the classes of tests to be conducted and a test procedure defines specific test

cases that will be used to demonstrate conformity with requirements. Both the plan and

procedure are designed to ensure that all functional requirements are satisfied, all

behavioral characteristics are achieved, all performance requirements are attained,

documentation is correct, and human engineered and other requirements are met.

124
Implementation

125
Implementation

Overview of the Technologies Used

The following technologies & tools have been used in this project:
 Visual Basic
 SQL Server

VB is an object based programming language. It has been used to implement the


student information management system. Visual Basic has the tools needed to develop
Windows applications.
 Data access features allows to create databases, front-end applications, and
scalable server-side components for most popular database formats, including
Microsoft SQL Server, ORACLE, and other enterprise-level databases.
 ActiveX™ technologies allows to use the functionality provided by other
programs, such as Microsoft Word, Microsoft Excel spreadsheet, Flash, etc.
 Internet capabilities make it easy to provide access to documents and
applications across the Internet or intranet from within your application, or to
create Internet server applications.

SQL Server Features


 Ease of installation, deployment, and use. SQL server includes a set of
administrative and development tools that simplify the ability to install, deploy,
manage, and use database.
 SQL server provides all the tools required to fine tune SQL server installations
running production online systems.
 SQL server is also capable of operating efficiently on the small, single user
system with minimal administrative overhead · Scalability

126
 The same SQL server 7.0 database engine can be used across platforms
ranging from laptop computers running Ms Windows 95/98/NT etc.
 The database engine is a robust server that can manage terabyte databases
being accessed by thousands of users. At the same time, when running at its
default settings, SQL server 7.0 has features such as dynamic self tuning that let
it work effectively on laptops and desktops without burdening users with
administrative tasks.
 Data warehousing: SQL server includes for extracting and analyzing summary
data online analytical processing (OLAP). It also includes tools for visually
designing databases and analyzing data using English based questions.
 System integration with other server software: It integrates with email, internet,
and windows.

Details of some important methods

Public Function connectDatabase() : This function is responsible for connecting to the

database. It creates a new connection object & tries to connect to the database.

Public Function closeConnection () : This method is called when the application is

terminated. It closes the open connection with the database.

Private Sub InitializeControls(): This procedure is available in every module to initialize

the controls of the form.

Private Sub InitializeGrid(): This procedure is responsible for initializing the data grid.

The data grid shows all the records in a table like structure.

Private Sub mnuitmStudentList_Click(): This procedure shows the list of all the students

enrolled with the institute.

Details of some other methods in forms like student, course, subject, result, etc.
127
Private Sub cmdList_Click(): This method is called when the user clicks the Hide/Show

button. This method is used to show all the records in a grid. If the grid is visible & the

user again presses this button, the software will hide the grid.

Private Sub cmdAdd_Click(): This method is called when the user tries to add a new

record. Most forms in the student information management system have this method.

Private Sub cmdDelete_Click(): This method is called when the user tries to delete a

record.

Private Sub cmdEdit_Click(): This method allows the user to edit a record.

Private Sub cmdUpdate_Click() : This method updates data in the database.

Private Sub cmdCancel_Click(): This procedure is used to cancel any updates made to

the recordset.

Private Sub cmdFirst_Click() : This method moves to the first record in the recordset.

Private Sub cmdLast_Click() : This method moves to the last record in the recordset.

Private Sub cmdNext_Click() : This method moves to the next record in the recordset.

Private Sub cmdPrevious_Click() : This method moves to the previous record in the

recordset.

Private Sub SetControls(bVal As Boolean): This procedure is used to lock/unlock the

textfields for editing.

Private Sub SetButtons(bVal As Boolean): This procedure is responsible for

enabling/disabling buttons. It also shows/hides buttons according to the current

operation (i.e., add, edit, etc.)

128
Software

Maintenance

129
Software Maintenance

Maintenance comes under the support phase. Maintenance accounts for more effort

than any other software engineering activity. It focuses on change associated with error

correction, adaptations required as the software's environment evolves, and changes

due to enhancements brought about by changing customer requirements. Four types of

changes are encountered during the support phase:

 Corrective Maintenance: Even with the best quality assurance activities, it is

likely that the customer will uncover defects in the software. Corrective

maintenance changes the software to correct defects.

 Adaptive Maintenance: Over time, the original environment (e.g., CPU, OS,

rules, external product characteristic) for which the software was developed is

likely to change. Adaptive maintenance results in modification to the software to

accommodate changes to its external environment.

 Perfective Maintenance: As the software is used, the customer will recognize

additional functions that will provide benefit. Perfective maintenance extends the

software beyond its original functional requirements.

 Preventive Maintenance: Computer software deteriorates due to change, and

because of this, preventive maintenance, often called software reengineering,

must be conducted to enable the software to serve the needs of its end users. In

essence, preventive maintenance makes changes to computer program so that it

can be more easily corrected, adapted, and enhanced.


130
Software Performance

The performance of the student system depends upon the speed and efficiency of the

user’s computer & the network speed if the database is kept on a remote server.

131
Software

Reliability

132
Reliability

Reliability is an important element of its overall software quality. If a program repeatedly

and frequently fails to perform, it matters little whether other software quality factors are

acceptable.

The application (project) developed by us has a reliability of 0.94 over six elapsed

processing hours.

133
Software

Quality

134
Software Quality Measures

Although there are several measures of software quality, we have taken the following

measures as an indicator in this project:

 Correctness

 Maintenance

 Integrity

 Usability

 Efficiency

 Portability

135
Cost

Estimation

136
Cost Estimation

In this project, we have used the COCOMO II model for cost estimation.

According to the COCOMO II Model, the project will cost between Rs. 32000 - 35000.

137
Future Scope

138
Future Scope of the Project

The Student Information Management System is the perfect software to manage

student records. The program's many features simplify record keeping & grading, saving

both time and money. The software has a students list manager, teachers list manager,

courses list manager, subjects list manager & the subject wise & overall result manager.

Every institute, university, or college maintains student records, teachers records,

course related details, subjects under a particular course. This software is very useful

for educational institutes, universities, & colleges because it allows them to maintain the

required database, so it has a good future.

More modules and features can easily be added in future to make this software more

useful. For example, attendance module, web interface module, etc can be added.

139
Bibliography

 Visual Basic in 21 days -Techmedia

 Interactive Visual Basic -Waite Group

 Visual Basic 6 Simplified (Educational CD) - Universal Teacher Publications

 MSDN - VB Help

 Software Engineering- A practitioner's approach.

140
Appendices

This project has been developed using Visual Basic 6.0 & SQL

It uses the ADO (ActiveX Data Objects for connecting to the database)

The project uses Microsoft's Data Grid (OLE DB) control for showing all the records at a

time.

141

You might also like