158
Title 2010 Student Information Management System Project By:Vikas

Studinfo Report

  • Upload
    vikas

  • View
    45

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Studinfo Report

Title

2010

Student Information Management SystemProject By:Vikas

Page 2: Studinfo Report

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

Page 3: Studinfo Report

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

Page 4: Studinfo Report

Project Category

This project falls under the following category:

RDBMS

Business Applications

4

Page 5: Studinfo Report

Tools/Platform, Languages to be used

Visual Basic 6

SQL Server

Operating System

Windows

Requirements Hardware

Pentium-4

512 MB RAM

5

Page 6: Studinfo Report

System Analysis

6

Page 7: Studinfo Report

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

Page 8: Studinfo Report

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

Page 9: Studinfo Report

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

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

9

Page 10: Studinfo Report

Analysis Reports

10

Page 11: Studinfo Report

Context Analysis Diagram

11

Page 12: Studinfo Report

First level Diagram

12

Page 13: Studinfo Report

Second Level Diagram

13

Page 14: Studinfo Report

Third Level Diagram

14

Page 15: Studinfo Report

Third level Diagram

15

Page 16: Studinfo Report

ERD

16

Page 17: Studinfo Report

Program

Structure

17

Page 18: Studinfo Report

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

Page 19: Studinfo Report

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

Page 20: Studinfo Report

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

Page 21: Studinfo Report

Tables

Tables

Student

Name Description Data Type

RollNoThe unique roll number of the student. (Primary

Key)nvarchar(10)

FirstName First name of the student. nvarchar(25)

LastName Last name of the student. nvarchar(25)

CourseIDThe course taken by the student. (Foreign key,

references CourseID in the Course table)nvarchar(5)

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)21

Page 22: Studinfo Report

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

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)

CourseID

The course name (Foreign key,

references CoursesID in the Course

table)

nvarchar(5)

TeacherID

The teacher who teaches this subject

(Foreign key, references TeacherID in

the Teacher table)

nvarchar(6)

22

Page 23: Studinfo Report

Result

Name Description Data Type

RollNoRoll number of the student (Foreign key,

references RollNo in the Student table)nvarchar(10)

SubjectIDSubject name (Foreign key, references

SubjectID in the Subject table)nvarchar(5)

MarksMarks of the student in a particular

subject.Integer

Status

Status of the subject. If the status is

"SC", it means successfully completed. If

the status is "NC", it means not

completed.

nvarchar(2)

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:

23

Page 24: Studinfo Report

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.

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"

24

Page 25: Studinfo Report

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.

25

Page 26: Studinfo Report

Reports

Lists all the reports generated by the system.

Teachers Report

Students Report

Courses Report

Each of these reports can be easily printed.

26

Page 27: Studinfo Report

System Screens

27

Page 28: Studinfo Report

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.

28

Page 29: Studinfo Report

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.

29

Page 30: Studinfo Report

The Students Screen- Add Record Mode

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

30

Page 31: Studinfo Report

The Students Screen- Edit Record Mode

This screen allows the user to edit information about students.

31

Page 32: Studinfo Report

The Students Screen- Delete Record Mode

This screen allows the user to delete records of students.

32

Page 33: Studinfo Report

The Courses List Screen

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

delete course-related information.

33

Page 34: Studinfo Report

The Subjects List Screen

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

34

Page 35: Studinfo Report

The Teachers List Screen

This screen shows details about teachers.

35

Page 36: Studinfo Report

The Result of all Students Screen

This screen shows the subject wise marks of students.

36

Page 37: Studinfo Report

The Result by Roll Number Screen

This screen shows the result of a particular student.

37

Page 38: Studinfo Report

The Teachers Report

38

Page 39: Studinfo Report

The Students Report

39

Page 40: Studinfo Report

The Courses Report

40

Page 41: Studinfo Report

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.

41

Page 42: Studinfo Report

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.

42

Page 43: Studinfo Report

CODE

43

Page 44: Studinfo Report

The general Module – mainModule

Public studentsCon As ADODB.Connection

Public Sub main()Call connectDatabasefrmMain.ShowEnd 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 FunctionerrCheck: MsgBox Err.Description MsgBox "The application will be closed." EndEnd Function

Public Function closeConnection() studentsCon.CloseEnd Function

44

Page 45: Studinfo Report

The Main Screen – frmMain

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

Private Sub Form_Load() 'set the connection to the main connection Set db = studentsCon Call InitializeControlsEnd Sub'procedure to resize the gridPrivate 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 / 2End Sub'initialize the controls on the formPrivate Sub InitializeControls()'set the forecolor of the title labellblTitle.ForeColor = RGB(211, 211, 211)End Sub'initialize the grid on the formPrivate Sub InitializeGrid()Set adoPrimaryRS = New ADODB.RecordsetadoPrimaryRS.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.

45

Page 46: Studinfo Report

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"

46

Page 47: Studinfo Report

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 = adoPrimaryRSEnd Sub

Private Sub Form_Unload(Cancel As Integer) 'close the connection with the database Call closeConnection EndEnd Sub

'menu for course listPrivate Sub mnuCoursesList_Click()frmCourse.Show 0, MeEnd Sub

'this procedure shows the student form' in the add new modePrivate 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_ClickEnd Sub

'allows the user to delete student records

47

Page 48: Studinfo Report

Private Sub mnuitmDelete_Click()If frmStudent.Visible = True Then Exit Sub'show the form with listfrmStudent.cmdList_ClickfrmStudent.Show 0, Me'set focus on the delete buttonfrmStudent.cmdDelete.SetFocusEnd Sub'allw the users to edit a student recordPrivate Sub mnuitmEdit_Click()If frmStudent.Visible = True Then Exit Sub'show the form with listfrmStudent.cmdList_ClickfrmStudent.Show 0, Me'allow the users to edit a recordfrmStudent.cmdEdit_ClickEnd Sub'shows the result formPrivate Sub mnuitmResultAll_Click()frmResult.Show 0, MeEnd Sub'shows the result by roll number formPrivate Sub mnuitmResultbyRoll_Click()frmgetResult.Show 0, MeEnd Sub'show the details of all the students in the main windowPrivate 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

48

Page 49: Studinfo Report

End IfEnd Sub'show the course reportPrivate Sub mnurptCourses_Click()rptCourse.Show 0, MeEnd Sub

'show the student reportPrivate Sub mnurptStudents_Click()rptStudent.Show 0, MeEnd Sub

'show the teacher reportPrivate Sub mnurptTeachers_Click()rptTeacher.Show 0, MeEnd Sub

'show all the subjects availablePrivate Sub mnuSubjectsList_Click()frmSubject.Show 0, MeEnd Sub'show the details of all teachersPrivate Sub mnuTeachersList_Click()frmTeacher.Show 0, MeEnd Sub

49

Page 50: Studinfo Report

The Course Screen- frmCourse

'variable declaration'connection objectDim db As ADODB.Connection'recordset objectDim WithEvents adoPrimaryRS As ADODB.Recordset'variable to bookmark current locationDim mvBookMark As Variant'variable for editingDim mbEditFlag As Boolean'variable for adding new recordsDim mbAddNewFlag As Boolean'flag for data changesDim mbDataChanged As Boolean

'show/hide all records gridPrivate Sub cmdList_Click()'shows all the records in a gridIf 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 SubElse cmdList.Caption = "List" cmdList.ToolTipText = "Show List" 'resize the window Me.Height = Me.Height - dgrid.Height - 150 Set dgrid.DataSource = Nothing dgrid.Visible = FalseEnd IfEnd Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer) 'suppress any error messages Response = 0 dgrid.DataChanged = FalseEnd Sub

Private Sub Form_Load()

50

Page 51: Studinfo Report

'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 InitializeControlsEnd Sub

Private Sub Form_Unload(Cancel As Integer) Screen.MousePointer = vbDefault Set db = Nothing frmMain.SetFocusEnd 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

51

Page 52: Studinfo Report

Case adRsnRequery Case adRsnResynch Case adRsnUndoAddNew Case adRsnUndoDelete Case adRsnUndoUpdate Case adRsnUpdate End Select

If bCancel Then adStatus = adStatusCancelEnd Sub

'procedure for adding a new recordPrivate 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 codeAddErr: MsgBox Err.DescriptionEnd Sub

'procedure for deleting a recordPrivate 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

52

Page 53: Studinfo Report

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 codeDeleteErr: MsgBox Err.DescriptionEnd Sub

'edit a record in the recordsetPrivate 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 codeEditErr: MsgBox Err.DescriptionEnd Sub

'cancel any updates madePrivate Sub cmdCancel_Click() On Error Resume Next 'show/hide buttons SetButtons True

53

Page 54: Studinfo Report

'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 databasePrivate 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

54

Page 55: Studinfo Report

SetControls True 'set data changed to false mbDataChanged = False Exit Sub'error handling codeUpdateErr: MsgBox Err.DescriptionEnd Sub

Private Sub cmdClose_Click() Unload MeEnd Sub

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

Exit Sub'error handling codeGoFirstError: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoLastError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the next recordPrivate Sub cmdNext_Click() On Error GoTo GoNextError 'if not EOF(end of file)then 'move to the last record

55

Page 56: Studinfo Report

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 SubGoNextError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the previous recordPrivate 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 codeGoPrevError: MsgBox Err.DescriptionEnd 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 buttonsPrivate Sub SetButtons(bVal As Boolean) 'show/hide buttons cmdAdd.Visible = bVal cmdEdit.Visible = bVal cmdUpdate.Visible = Not bVal

56

Page 57: Studinfo Report

cmdCancel.Visible = Not bVal cmdDelete.Visible = bVal cmdClose.Visible = bVal 'enable/disable buttons cmdNext.Enabled = bVal cmdFirst.Enabled = bVal cmdLast.Enabled = bVal cmdPrevious.Enabled = bValEnd 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 NextEnd 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

57

Page 58: Studinfo Report

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 = 2400End Sub

58

Page 59: Studinfo Report

The Subject Screen - frmSubject

'variable declaration'connection objectDim db As ADODB.Connection'recordset objectDim WithEvents adoPrimaryRS As ADODB.Recordset'variable to bookmark current locationDim mvBookMark As Variant'variable for editingDim mbEditFlag As Boolean'variable for adding new recordsDim mbAddNewFlag As Boolean'flag for data changesDim mbDataChanged As Boolean

'show/hide all records gridPrivate Sub cmdList_Click()'shows all the records in a gridIf 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 SubElse cmdList.Caption = "List" cmdList.ToolTipText = "Show List" 'resize the window Me.Height = Me.Height - dgrid.Height - 180 Set dgrid.DataSource = Nothing dgrid.Visible = FalseEnd IfEnd Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer) 'suppress any error messages Response = 0 dgrid.DataChanged = FalseEnd Sub

Private Sub Form_Load()

59

Page 60: Studinfo Report

'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 InitializeControlsEnd Sub

Private Sub Form_Unload(Cancel As Integer) Screen.MousePointer = vbDefault Set db = Nothing 'set focus on the main window frmMain.SetFocusEnd 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

60

Page 61: Studinfo Report

Case adRsnRequery Case adRsnResynch Case adRsnUndoAddNew Case adRsnUndoDelete Case adRsnUndoUpdate Case adRsnUpdate End Select

If bCancel Then adStatus = adStatusCancelEnd Sub

'procedure for adding a new recordPrivate 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 codeAddErr: MsgBox Err.DescriptionEnd Sub

'procedure for deleting a recordPrivate 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

61

Page 62: Studinfo Report

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 codeDeleteErr: MsgBox Err.DescriptionEnd Sub

'edit a record in the recordsetPrivate 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 codeEditErr: MsgBox Err.DescriptionEnd Sub

'cancel any updates madePrivate Sub cmdCancel_Click() On Error Resume Next 'show/hide buttons SetButtons True

62

Page 63: Studinfo Report

'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 databasePrivate 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

63

Page 64: Studinfo Report

SetControls True 'set data changed to false mbDataChanged = False Exit Sub'error handling codeUpdateErr: MsgBox Err.DescriptionEnd Sub

Private Sub cmdClose_Click() Unload MeEnd Sub

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

Exit Sub'error handling codeGoFirstError: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoLastError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the next recordPrivate Sub cmdNext_Click() On Error GoTo GoNextError 'if not EOF(end of file)then 'move to the last record

64

Page 65: Studinfo Report

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 SubGoNextError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the previous recordPrivate 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 codeGoPrevError: MsgBox Err.DescriptionEnd 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 buttonsPrivate Sub SetButtons(bVal As Boolean) 'show/hide buttons cmdAdd.Visible = bVal cmdEdit.Visible = bVal cmdUpdate.Visible = Not bVal

65

Page 66: Studinfo Report

cmdCancel.Visible = Not bVal cmdDelete.Visible = bVal cmdClose.Visible = bVal 'enable/disable buttons cmdNext.Enabled = bVal cmdFirst.Enabled = bVal cmdLast.Enabled = bVal cmdPrevious.Enabled = bValEnd 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 = bValEnd 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"

66

Page 67: Studinfo Report

'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

67

Page 68: Studinfo Report

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 = adoPrimaryRSEnd Sub

68

Page 69: Studinfo Report

The Teacher Screen – frmTeacher

'variable declaration'connection objectDim db As ADODB.Connection'recordset objectDim WithEvents adoPrimaryRS As ADODB.Recordset'variable to bookmark current locationDim mvBookMark As Variant'variable for editingDim mbEditFlag As Boolean'variable for adding new recordsDim mbAddNewFlag As Boolean'flag for data changesDim mbDataChanged As Boolean

'show/hide all records gridPrivate Sub cmdList_Click()'shows all the records in a gridIf 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 SubElse cmdList.Caption = "List" cmdList.ToolTipText = "Show List" 'resize the window Me.Width = Me.Width - dgrid.Width - 150 Set dgrid.DataSource = Nothing dgrid.Visible = FalseEnd IfEnd Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer) 'suppress any error messages Response = 0 dgrid.DataChanged = FalseEnd Sub

Private Sub Form_Load() 'set the connection

69

Page 70: Studinfo Report

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 InitializeControlsEnd Sub

Private Sub Form_Unload(Cancel As Integer) Screen.MousePointer = vbDefault Set db = Nothing frmMain.SetFocusEnd 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

70

Page 71: Studinfo Report

Case adRsnUndoDelete Case adRsnUndoUpdate Case adRsnUpdate End Select

If bCancel Then adStatus = adStatusCancelEnd Sub

'procedure for adding a new recordPrivate 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 codeAddErr: MsgBox Err.DescriptionEnd Sub

'procedure for deleting a recordPrivate 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

71

Page 72: Studinfo Report

'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 codeDeleteErr: MsgBox Err.DescriptionEnd Sub

'edit a record in the recordsetPrivate 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 codeEditErr: MsgBox Err.DescriptionEnd Sub

'cancel any updates madePrivate Sub cmdCancel_Click() On Error Resume Next 'show/hide buttons SetButtons True 'lock the text fields SetControls True 'set the edit flag to false

72

Page 73: Studinfo Report

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 databasePrivate 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

73

Page 74: Studinfo Report

Exit Sub'error handling codeUpdateErr: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoFirstError: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoLastError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the next recordPrivate 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

74

Page 75: Studinfo Report

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 SubGoNextError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the previous recordPrivate 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 codeGoPrevError: MsgBox Err.DescriptionEnd 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 buttonsPrivate 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

75

Page 76: Studinfo Report

'enable/disable buttons cmdNext.Enabled = bVal cmdFirst.Enabled = bVal cmdLast.Enabled = bVal cmdPrevious.Enabled = bValEnd 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 NextEnd 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

76

Page 77: Studinfo Report

'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 = 4380End Sub

77

Page 78: Studinfo Report

The Result All Screen- frmResult

'variable declaration'connection objectDim db As ADODB.Connection'recordset objectDim WithEvents adoPrimaryRS As ADODB.Recordset'variable to bookmark current locationDim mvBookMark As Variant'variable for editingDim mbEditFlag As Boolean'variable for adding new recordsDim mbAddNewFlag As Boolean'flag for data changesDim mbDataChanged As Boolean

'show/hide all records gridPrivate Sub cmdList_Click()'shows all the records in a gridIf 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 SubElse cmdList.Caption = "List" cmdList.ToolTipText = "Show List" 'resize the window Me.Height = Me.Height - dgrid.Height - 150 Set dgrid.DataSource = Nothing dgrid.Visible = FalseEnd IfEnd 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

78

Page 79: Studinfo Report

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 InitializeControlsEnd Sub

'this procedure is called when the form is'unloaded from the memoryPrivate Sub Form_Unload(Cancel As Integer) Screen.MousePointer = vbDefault Set db = Nothing 'set focus on the main window frmMain.SetFocusEnd 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

79

Page 80: Studinfo Report

Case adRsnUndoAddNew Case adRsnUndoDelete Case adRsnUndoUpdate Case adRsnUpdate End Select

If bCancel Then adStatus = adStatusCancelEnd Sub

'procedure for adding a new recordPrivate 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 codeAddErr: MsgBox Err.DescriptionEnd Sub

'procedure for deleting a recordPrivate 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

80

Page 81: Studinfo Report

.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 codeDeleteErr: MsgBox Err.DescriptionEnd Sub

'edit a record in the recordsetPrivate 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 codeEditErr: MsgBox Err.DescriptionEnd Sub

'cancel any updates madePrivate Sub cmdCancel_Click() On Error Resume Next 'show/hide buttons SetButtons True 'lock the text fields SetControls True

81

Page 82: Studinfo Report

'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 databasePrivate 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

82

Page 83: Studinfo Report

mbDataChanged = False Exit Sub'error handling codeUpdateErr: MsgBox Err.DescriptionEnd Sub'procedure to close the result formPrivate Sub cmdClose_Click() Unload MeEnd Sub

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

Exit Sub'error handling codeGoFirstError: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoLastError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the next recordPrivate 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

83

Page 84: Studinfo Report

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 SubGoNextError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the previous recordPrivate 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 codeGoPrevError: MsgBox Err.DescriptionEnd 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 buttonsPrivate 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

84

Page 85: Studinfo Report

cmdClose.Visible = bVal 'enable/disable buttons cmdNext.Enabled = bVal cmdFirst.Enabled = bVal cmdLast.Enabled = bVal cmdPrevious.Enabled = bValEnd 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 NextEnd 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"

85

Page 86: Studinfo Report

'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"

86

Page 87: Studinfo Report

'set the width of columns dgrid.Columns(0).Width = 1000 dgrid.Columns(1).Width = 900 dgrid.Columns(2).Width = 800 dgrid.Columns(3).Width = 800End Sub'when any error occurs in the gridPrivate Sub dgrid_Error(ByVal DataError As Integer, Response As Integer) 'suppress any error messages Response = 0 'set the data changed to false dgrid.DataChanged = FalseEnd 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 IfEnd IfEnd Sub

'this procedure is called when the' focus is lostPrivate Sub txtFields_LostFocus(Index As Integer)'check if the user is adding a new recordIf Trim(txtFields(2).Text) = "" Then Exit SubIf 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 IfEnd Sub

87

Page 88: Studinfo Report

The Result by Roll No Screen - frmgetResult

'connection objectDim 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)

88

Page 89: Studinfo Report

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 SuberrCheck: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 = 0End Sub

'this procedure is called when the'form is unloaded from memoryPrivate Sub Form_Unload(Cancel As Integer)'se the connection to nothingSet db = Nothing'set the focus on the main window

89

Page 90: Studinfo Report

frmMain.SetFocusEnd Sub

90

Page 91: Studinfo Report

The Student Screen – frmStudent

'variable declaration'connection objectDim db As ADODB.Connection'recordset objectDim WithEvents adoPrimaryRS As ADODB.Recordset'variable to bookmark current locationDim mvBookMark As Variant'variable for editingDim mbEditFlag As Boolean'variable for adding new recordsDim mbAddNewFlag As Boolean'flag for data changesDim mbDataChanged As Boolean

'show/hide all records gridPublic Sub cmdList_Click()'shows all the records in a gridIf 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 SubElse cmdList.Caption = "List" cmdList.ToolTipText = "Show List" 'resize the window Me.Height = Me.Height - dgrid.Height - 150 Set dgrid.DataSource = Nothing dgrid.Visible = FalseEnd IfEnd Sub

Private Sub dgrid_Error(ByVal DataError As Integer, Response As Integer) 'suppress any error messages Response = 0 dgrid.DataChanged = FalseEnd Sub

Private Sub Form_Load()

91

Page 92: Studinfo Report

'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,State,PostalCode from Student Order by RollNo", db, adOpenStatic, adLockOptimistic mbDataChanged = False 'call procedure to initialize the 'controls on the form Call InitializeControlsEnd Sub

Private Sub Form_Unload(Cancel As Integer) Screen.MousePointer = vbDefault Set db = Nothing 'set focus on the main window frmMain.SetFocusEnd 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

92

Page 93: Studinfo Report

Case adRsnRequery Case adRsnResynch Case adRsnUndoAddNew Case adRsnUndoDelete Case adRsnUndoUpdate Case adRsnUpdate End Select

If bCancel Then adStatus = adStatusCancelEnd Sub

'procedure for adding a new recordPublic 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 codeAddErr: MsgBox Err.DescriptionEnd Sub

'procedure for deleting a recordPrivate 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

93

Page 94: Studinfo Report

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 codeDeleteErr: MsgBox Err.DescriptionEnd Sub

'edit a record in the recordsetPublic 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 codeEditErr: MsgBox Err.DescriptionEnd Sub

'cancel any updates madePrivate Sub cmdCancel_Click() On Error Resume Next 'show/hide buttons SetButtons True

94

Page 95: Studinfo Report

'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 databasePrivate 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

95

Page 96: Studinfo Report

SetControls True 'set data changed to false mbDataChanged = False Exit Sub'error handling codeUpdateErr: MsgBox Err.DescriptionEnd Sub

Private Sub cmdClose_Click() Unload MeEnd Sub

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

Exit Sub'error handling codeGoFirstError: MsgBox Err.DescriptionEnd Sub

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

Exit Sub'error handling codeGoLastError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the next recordPrivate Sub cmdNext_Click() On Error GoTo GoNextError 'if not EOF(end of file)then 'move to the last record

96

Page 97: Studinfo Report

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 SubGoNextError: MsgBox Err.DescriptionEnd Sub

'procedure to move to the previous recordPrivate 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 codeGoPrevError: MsgBox Err.DescriptionEnd 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 buttonsPrivate Sub SetButtons(bVal As Boolean) 'show/hide buttons cmdAdd.Visible = bVal cmdEdit.Visible = bVal cmdUpdate.Visible = Not bVal

97

Page 98: Studinfo Report

cmdCancel.Visible = Not bVal cmdDelete.Visible = bVal cmdClose.Visible = bVal 'enable/disable buttons cmdNext.Enabled = bVal cmdFirst.Enabled = bVal cmdLast.Enabled = bVal cmdPrevious.Enabled = bValEnd 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 = FalseEnd 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

98

Page 99: Studinfo Report

'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 InitializeGridEnd 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"

99

Page 100: Studinfo Report

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 = 1000End 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 IfEnd Sub

100

Page 101: Studinfo Report

Code

Optimization

101

Page 102: Studinfo Report

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.

102

Page 103: Studinfo Report

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.

103

Page 104: Studinfo Report

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.

104

Page 105: Studinfo Report

Software Testing

Techniques

105

Page 106: Studinfo Report

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

106

Page 107: Studinfo Report

White Box Testing

Techniques

107

Page 108: Studinfo Report

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

108

Page 109: Studinfo Report

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 E1 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 2n 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 2n

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

109

Page 110: Studinfo Report

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 (D1, 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:

C1 : B1 & 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.

110

Page 111: Studinfo Report

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

111

Page 112: Studinfo Report

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.

112

Page 113: Studinfo Report

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.

113

Page 114: Studinfo Report

114

Page 115: Studinfo Report

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.

115

Page 116: Studinfo Report

Black Box

Testing

116

Page 117: Studinfo Report

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:

117

Page 118: Studinfo Report

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.

118

Page 119: Studinfo Report

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.

119

Page 120: Studinfo Report

Software Testing

Strategies

120

Page 121: Studinfo Report

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.

121

Page 122: Studinfo Report

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.

122

Page 123: Studinfo Report

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.

123

Page 124: Studinfo Report

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.

124

Page 125: Studinfo Report

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.

125

Page 126: Studinfo Report

Implementation

126

Page 127: Studinfo Report

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

127

Page 128: Studinfo Report

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.

128

Page 129: Studinfo Report

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.)

129

Page 130: Studinfo Report

Software

Maintenance

130

Page 131: Studinfo Report

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.

131

Page 132: Studinfo Report

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.

132

Page 133: Studinfo Report

Software

Reliability

133

Page 134: Studinfo Report

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.

134

Page 135: Studinfo Report

Software

Quality

135

Page 136: Studinfo Report

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

136

Page 137: Studinfo Report

Cost

Estimation

137

Page 138: Studinfo Report

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.

138

Page 139: Studinfo Report

Future Scope

139

Page 140: Studinfo Report

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.

140

Page 141: Studinfo Report

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.

141

Page 142: Studinfo Report

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.

142