-
December 10th, 2013, 12:56 PM
#1
Calculating the score at the end of a test and then saving it into Access.
Hi, I've got a problem with my spelling program where I'm not able to display the correct score at the end of the test. Also, after somebody's help with that, I'd greatly appreciate help from someone to show me how to then save that score into access. Thanks.
Btw. The 'Test' form 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.
I've tried to display that score for the user but no matter what I do, it always shows the answers that the user has typed in and no score. (Even though I don't actually want these answers displaying there, just the score...)
This is the code that I've so far:
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.OLEDB.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
MsgBox(Ansrs(0, r))
If Ansrs(0, r).ToLower = Ansrs(1, r).ToLower Then
Score = Score + 2
MsgBox("You have scored " & Score)
End If
Next
End Sub
End Class
P.S. 'Exit' as well as 'Previous' button don't have anything to do with this. Just thought that I might include the whole form instead of some bits though.
-
December 12th, 2013, 03:37 PM
#2
Re: Calculating the score at the end of a test and then saving it into Access.
-
December 12th, 2013, 04:56 PM
#3
Re: Calculating the score at the end of a test and then saving it into Access.
This doesn't have any context here, most likely. Use DEBUG to produce the current results
Code:
If Ansrs(0, r).ToLower = Ansrs(1, r).ToLower Then
Tags for this Thread
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
|