-
December 8th, 2013, 03:39 PM
#1
Spelling program with linking back to the database. (VB.NET 2010 & Access 2010)
Hi everyone! First of all, I just want to say that I'm new to VB and if some of those things are easy to do and I'm asking for help with them, then now you know why. Anyway, my task is to create a program that will help students with their spelling. The program has to do these things:
Allow users to log in either as staff and/or pupils (DONE)
Allow staff to add words and definitions to the system (DONE)
Display a ten question spelling test (DONE)
Calculate and display a student's score at the end of the test
Store pupils' score (In the database that I've already created. It includes all the login details, words, definitions, etc.)
Provide analysis of pupils' progress
And also, the system should score each of the ten words using the following rules: • If the pupil’s spelling is correct - 2 marks (Every single letter correct) • If there is a minor error - 1 mark (1 letter wrong) • If there is a major error - 0 mark (More than 1 letter wrong)
Basically, I need help with all the things that aren't marked as 'DONE' and what I would like you guys to help me with is to just show me how to do these things. It's hard to explain what I actually need but I hope that at least some of you know what I need. If you have any questions then I'll do my best to answer them! Thanks in advance for all the help!
Example of how you could help me. (For those of you who don't know what I mean.) For example you choose to help me with this: - Calculate and display a student's score at the end of the test. By telling me what to do or by showing me the code. But as I said earlier, if you have any questions about anything then just ask!
-
December 8th, 2013, 09:16 PM
#2
Re: Spelling program with linking back to the database. (VB.NET 2010 & Access 2010)
You'd have to post what you have, and what problem you are having. If you have a test, it should have answers. Not sure how you'd not catch a misspelled an answer. Make sure that you use CODE TAGS
-
December 9th, 2013, 06:03 AM
#3
Re: Spelling program with linking back to the database. (VB.NET 2010 & Access 2010)
I guess I'll just start with all of my forms, how they are linked to each other, what they do, (or what they are supposed to do) etc.
Main form- Splash screen, takes you to the login form. (No problems with that so no need to go into further details here)
Login form- Includes a text box where you can type in the username, a text box where you can type in the password, a button that will allow you to log in as a teacher and an appropriate form for that will show up(StaffMenu) and a button that will allow you to log in as a student and an appropriate form for that will show up(StudentMenu). I don't have any problems with this form just showing it so you can understand everything easier, later.
All the code that I have for this form:
Public Class frmLogin
Private Sub cmdLoginT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoginT.Click
' Checks whether username or password field is empty
If txtPass.Text = "" Or txtUsername.Text = "" Then
MessageBox.Show("Please complete the required fields.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' If Both fields were filled in, then check whether the user exists in the database
' Connect to the database
Dim Conn As New System.Data.OleDb.OleDbConnection()
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database for VB.accdb"
'Try
' Conn.Open()
Dim SQL As String = "SELECT * FROM UserTable WHERE username='" & txtUsername.Text & "' AND password = '" & txtPass.Text & "'"
Dim SQLComm As New System.Data.OleDb.OleDbCommand(SQL)
' Open Database Connection
SQLComm.Connection = Conn
Conn.Open()
Dim SQLRdr As System.Data.OleDb.OleDbDataReader = SQLComm.ExecuteReader()
' Makes sure that you can't login as staff to the student area and that you can't login as student to the staff area
If SQLRdr.Read() Then
If (SQLRdr.Item("Position")) = "Staff" Then
MsgBox("You have successfully logged in!")
' After successfully logging in, the 'Staff Menu' form will show up
frmStaffMenu.Show()
Me.Close()
ElseIf (SQLRdr.Item("Position")) = "Student" Then
MsgBox("You don't have access to this area!")
txtPass.Text = ""
txtUsername.Text = ""
End If
Else
' If a user has entered wrong username and/or password combination then an error message will come up
MessageBox.Show("Username and Password do not match.", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' Clear all fields so the user can quickly enter the details again
txtPass.Text = ""
txtUsername.Text = ""
' Focus on the 'Username' field
txtUsername.Focus()
End If
'Catch ex As Exception
'MessageBox.Show("Failed to connect to Database.", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'End Try
End If
End Sub
Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
' User clicking on clear button will clear all the fields and refocus to the 'Username' field to make everything easier and quicker
txtUsername.Text = ""
txtPass.Text = ""
txtUsername.Focus()
End Sub
Private Sub cmdLoginS_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdLoginS.Click
' Checks whether username and/or password fields are empty
If txtPass.Text = "" Or txtUsername.Text = "" Then
MessageBox.Show("Please complete the required fields.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' If Both fields were filled in, then check whether the user exists in the database
' Connect to the database
Dim Conn As New System.Data.OleDb.OleDbConnection()
Conn.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database for VB.accdb"
' Try
' Conn.Open()
Dim SQL As String = "SELECT * FROM UserTable WHERE username='" & txtUsername.Text & "' AND password = '" & txtPass.Text & "'"
Dim SQLComm As New System.Data.OleDb.OleDbCommand(SQL)
' Open Database Connection
SQLComm.Connection = Conn
Conn.Open()
Dim SQLRdr As System.Data.OleDb.OleDbDataReader = SQLComm.ExecuteReader()
' Makes sure that you can't login as staff to the student area and that you can't login as student to the staff area
If SQLRdr.Read() Then
If (SQLRdr.Item("Position")) = "Student" Then
MsgBox("You have successfully logged in!")
' After successfully logging in, the 'Student Menu' form will show up
frmStudentMenu.Show()
Me.Close()
ElseIf (SQLRdr.Item("Position")) = "Staff" Then
MsgBox("You don't have access to this area!")
txtPass.Text = ""
txtUsername.Text = ""
End If
Else
' If a user has entered wrong username and/or password combination then an error message will come up
MessageBox.Show("Username and Password do not match.", "Authentication Failure", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
' Clear all fields so the user can quickly enter the details again
txtPass.Text = ""
txtUsername.Text = ""
' Focus on the 'Username' field
txtUsername.Focus()
End If
'Catch ex As Exception
' MessageBox.Show("Failed to connect to Database.", "Database Connection Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
'End Try
End If
End Sub
Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' When a user will press the exit button, a message box will appear asking whether they want to close the program and if a user clicks 'Yes' then
' the whole program will close but if they click 'No' then the message box will simply dissapear
Dim Result As DialogResult
Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)
If Result = Windows.Forms.DialogResult.Yes Then
' Makes sure that the program will actually fully close
Application.Exit()
Else
End If
End Sub
End Class
Staff menu form- A simple form with which you can easily be directed to any other form you want. In this case, 'Leaderboards'(Doesn't matter for now), 'Create test' and 'Check individual progress'(This form is supposed to allow the teacher to give some kind of comment after each test that the student has completed. I haven't created a form for that yet because there are other, more important things to do first, such as calculating and saving score as well as how to differentiate whether a student has done a major or minor mistake.)
Code:
Public Class frmStaffMenu
Private Sub frmStaffMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnLeader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeader.Click
' Once the button is clicked, 'Leaderboards' form will show up
frmLeaderboards.Show()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' When a user will press the exit button, a message box will appear asking whether they want to close the program and if a user clicks 'Yes' then
' the whole program will close but if they click 'No' then the message box will simply dissapear
Dim Result As DialogResult
Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)
If Result = Windows.Forms.DialogResult.Yes Then
' Makes sure that the program will actually fully close
Application.Exit()
Else
End If
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
' The current form will close and go back to the previous form
Me.Close()
End Sub
Private Sub btnCreateTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTest.Click
' Once the button is clicked, 'Create test' form will show up
frmCreateTest.Show()
End Sub
End Class
Student menu form- The same as for the teacher but with different forms that they can be directed to. Again, a simple menu(?) form.
Code:
Public Class frmStudentMenu
Private Sub frmStudentMenu_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub btnLeader_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLeader.Click
' Once the button is clicked, 'Leaderboards' form will show up
frmLeaderboards1.Show()
End Sub
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' When a user will press the exit button, a message box will appear asking whether they want to close the program and if a user clicks 'Yes' then
' the whole program will close but if they click 'No' then the message box will simply dissapear
Dim Result As DialogResult
Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)
If Result = Windows.Forms.DialogResult.Yes Then
' Makes sure that the program will actually fully close
Application.Exit()
Else
End If
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
' The current form will close and go back to the previous form
Me.Close()
End Sub
Private Sub btnDoTest_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDoTest.Click
' Once the button is clicked, 'Test' form will show up
frmTest.ShowDialog()
End Sub
End Class
Create test form- This is a form that I use to create a test in. It includes a label that just tells the user to complete all the fields and then click the save button, label that says 'Definition' with a text box under it where a teacher will be able to actually type in the definition, a label that says 'Answer' with a text box under it where a teacher will be able to type in the answer, a label that says 'Week number' with a text box next to it where a teacher will be able to type in the week number as well as a button save which saves all the data the teacher has typed in and saves it in the database in a table called 'TestData'. No problems with this form either.
Code:
Imports System.Data.OleDb
Public Class frmCreateTest
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' When a user will press the exit button, a message box will appear asking whether they want to close the program and if a user clicks 'Yes' then
' the whole program will close but if they click 'No' then the message box will simply dissapear
Dim Result As DialogResult
Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)
If Result = Windows.Forms.DialogResult.Yes Then
' Makes sure that the program will actually fully close
Application.Exit()
Else
End If
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
' The current form will close and go back to the previous form
Me.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
' Open Connection
Dim MyDB, MyStr As String
Dim Connection As New System.Data.OleDb.OleDbConnection()
MyStr = ("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Database for VB.accdb")
Connection = New OleDb.OleDbConnection(MyStr)
Connection.Open()
' Checks whether any of the fields are empty if yes, then an error message will show up
If txtDef.Text = "" Or txtAns.Text = "" Or txtWeekNo.Text = "" Then
MessageBox.Show("Please complete the required fields.", "Authentication Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
' Adding a new record to the database
MyDB = "INSERT INTO TestData (Definition,Answer,WeekNumber) values ('" & txtDef.Text & "','" & txtAns.Text & "','" & txtWeekNo.Text & "')"
Dim Run = New OleDb.OleDbCommand
Try
' If record added successfully then a message box will show up
Run = New OleDb.OleDbCommand(MyDB, Connection)
Run.ExecuteNonQuery()
MsgBox("Record has been successfully added!")
txtDef.Text = ""
txtAns.Text = ""
txtWeekNo.Text = ""
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "OleDb Error")
End Try
End If
End Sub
End Class
Test form- This is the form which actually displays the test for the student. It includes these labels: 'Week number', 'lblWeekNo2', (This lable will actually change to a week number once the test starts, some bits of the test show up once the user actually clicks the start button and you can see that in the code below.) 'Definition', 'Answer', 'lblInfo' (This label changes as the the test progresses, it shows when the test starts and then simply displays the number of the questions, however, once the test is finished it changes to ''You have successfully completed the test! Well done!'') 'lblDef', (This label is linked with the database to actually show the definition to the user.) a text box which allows the student to actually type in the answer as well as two buttons. 'Start' (Starts the test and shows some bits and hides others[shown in the code below]) and 'Next' which basically just shows the next definition to the user.
P.S. I tried to display that score for the user but no matter what I do, it always shows 'You have scored 2' and this is where I need help. As well as how to then save that score with the week number and student details(Maybe their login?) into the database.
Code:
Public Class frmTest
Dim Conn As New System.Data.OleDb.OleDbConnection()
Dim Score As Integer = 0
Dim Ansrs(1, 9) As String
Dim r As Integer = 1
Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click
' When a user will press the exit button, a message box will appear asking whether they want to close the program and if a user clicks 'Yes' then
' the whole program will close but if they click 'No' then the message box will simply dissapear
Dim Result As DialogResult
Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)
If Result = Windows.Forms.DialogResult.Yes Then
' Makes sure that the program will actually fully close
Application.Exit()
Else
End If
End Sub
Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click
' Instead of just closing the form, it closes the form so that when you open it again, everything resets
Me.Dispose()
End Sub
Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Makes all the things invisible before the actual test starts
lblDef.Visible = False
lblWeekNo2.Visible = False
lblInfo.Visible = False
lblDefinition.Visible = False
txtAns.Visible = False
lblWeekNo.Visible = False
btnNxt.Visible = False
lblAnswer.Visible = False
' Opening the connection
Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLED B.12.0; Data Source=Database for VB.accdb")
Conn.Open()
End Sub
Private Sub btnNxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNxt.Click
If r = 10 Then
Ansrs(0, r - 1) = txtAns.Text
txtAns.Text = ""
FinishTest()
Else
Ansrs(1, r - 1) = txtAns.Text
r = r + 1
txtAns.Text = ""
StartTest()
End If
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
' Makes all the buttons that you will need in the test, visible. It'll show the field for the user to complete
txtAns.Visible = True
lblWeekNo.Visible = True
lblWeekNo2.Visible = True
lblDef.Visible = True
lblDefinition.Visible = True
btnStart.Visible = False
lblAnswer.Visible = True
' When the button 'Start the test!' is clicked, the 'StartTest' sub routine will start
StartTest()
End Sub
Private Sub StartTest()
' Making the 'Next' button visible to allow the user to complete the whole test
btnNxt.Visible = True
' Reading data from the database
Dim StringStart As String = "SELECT * FROM TestData WHERE WordNumber = " & r
Dim Comm As New OleDb.OleDbCommand(StringStart, Conn)
Dim RDR As OleDb.OleDbDataReader = Comm.ExecuteReader
RDR.Read()
lblDef.Text = RDR.Item("Definition")
Ansrs(0, r - 1) = RDR.Item("Answer")
lblWeekNo2.Text = RDR.Item("WeekNumber")
lblInfo.Visible = True
lblInfo.Text = r & "/10"
End Sub
Private Sub FinishTest()
lblInfo.Text = "You have successfully completed the test! Well done!"
lblInfo.Left = (Me.Width / 1.5) - (lblInfo.Width / 1.5)
' When the test is done, it makes all of the things that the user won't need anymore, invisible
lblDef.Visible = False
lblWeekNo2.Visible = False
btnNxt.Visible = False
lblWeekNo.Visible = False
txtAns.Visible = False
lblAnswer.Visible = False
lblDefinition.Visible = False
TestScore()
End Sub
Private Sub TestScore()
For r As Integer = 0 To 9
If Ansrs(0, r) = Ansrs(1, r) Then
Score = Score + 2
MsgBox("You have scored " & Score)
End If
Next
End Sub
End Class
I hope that this makes it at least a little bit clearer now... I'm going to leave the rest of the forms at least for now because this is what I think, would be best to do next.
Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|