Question Calculating the score at the end of a test and then saving it into Access.

Yhym

Member
Joined
Dec 8, 2013
Messages
7
Programming Experience
Beginner
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:

VB.NET:
[SIZE=2][FONT=arial]Public Class frmTest[/FONT]
[FONT=arial]    Dim Conn As New System.Data.OleDb.OleDbConnection()[/FONT]
[FONT=arial]    Dim Score As Integer = 0[/FONT]
[FONT=arial]    Dim Ansrs(1, 9) As String[/FONT]
[FONT=arial]    Dim r As Integer = 1[/FONT]
[FONT=arial]    Private Sub btnClose_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClose.Click[/FONT]
[FONT=arial]        ' 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 [/FONT]
[FONT=arial]        ' the whole program will close but if they click 'No' then the message box will simply dissapear [/FONT]
[FONT=arial]        Dim Result As DialogResult[/FONT]
[FONT=arial]        Result = MessageBox.Show("Are you sure you wish to close the program?", "Close program?", MessageBoxButtons.YesNo)[/FONT]
[FONT=arial]        If Result = Windows.Forms.DialogResult.Yes Then[/FONT]
[FONT=arial]            ' Makes sure that the program will actually fully close[/FONT]
[FONT=arial]            Application.Exit()[/FONT]
[FONT=arial]        Else[/FONT]
[FONT=arial]        End If[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Private Sub btnPrev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrev.Click[/FONT]
[FONT=arial]        ' Instead of just closing the form, it closes the form so that when you open it again, everything resets[/FONT]
[FONT=arial]        Me.Dispose()[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load[/FONT]
[FONT=arial]        ' Makes all the things invisible before the actual test starts[/FONT]
[FONT=arial]        lblDef.Visible = False[/FONT]
[FONT=arial]        lblWeekNo2.Visible = False[/FONT]
[FONT=arial]        lblInfo.Visible = False[/FONT]
[FONT=arial]        lblDefinition.Visible = False[/FONT]
[FONT=arial]        txtAns.Visible = False[/FONT]
[FONT=arial]        lblWeekNo.Visible = False[/FONT]
[FONT=arial]        btnNxt.Visible = False[/FONT]
[FONT=arial]        lblAnswer.Visible = False[/FONT]
[FONT=arial]        ' Opening the connection[/FONT]
[FONT=arial]        Conn = New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source=Database for VB.accdb")[/FONT]
[FONT=arial]        Conn.Open()[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]
[/FONT]
[FONT=arial]    Private Sub btnNxt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNxt.Click[/FONT]
[FONT=arial]        If r = 10 Then[/FONT]
[FONT=arial]            Ansrs(0, r - 1) = txtAns.Text[/FONT]
[FONT=arial]            txtAns.Text = ""[/FONT]
[FONT=arial]            FinishTest()[/FONT]
[FONT=arial]        Else[/FONT]
[FONT=arial]            Ansrs(1, r - 1) = txtAns.Text[/FONT]
[FONT=arial]            r = r + 1[/FONT]
[FONT=arial]            txtAns.Text = ""[/FONT]
[FONT=arial]            StartTest()[/FONT]
[FONT=arial]        End If[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]    Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click[/FONT]
[FONT=arial]        ' Makes all the buttons that you will need in the test, visible. It'll show the field for the user to complete[/FONT]
[FONT=arial]        txtAns.Visible = True[/FONT]
[FONT=arial]        lblWeekNo.Visible = True[/FONT]
[FONT=arial]        lblWeekNo2.Visible = True[/FONT]
[FONT=arial]        lblDef.Visible = True[/FONT]
[FONT=arial]        lblDefinition.Visible = True[/FONT]
[FONT=arial]        btnStart.Visible = False[/FONT]
[FONT=arial]        lblAnswer.Visible = True[/FONT]
[FONT=arial]        ' When the button 'Start the test!' is clicked, the 'StartTest' sub routine will start[/FONT]
[FONT=arial]        StartTest()[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]    Private Sub StartTest()[/FONT]
[FONT=arial]        ' Making the 'Next' button visible to allow the user to complete the whole test[/FONT]
[FONT=arial]        btnNxt.Visible = True[/FONT]
[FONT=arial]        ' Reading data from the database[/FONT]
[FONT=arial]        Dim StringStart As String = "SELECT * FROM TestData WHERE WordNumber = " & r[/FONT]
[FONT=arial]        Dim Comm As New OleDb.OleDbCommand(StringStart, Conn)[/FONT]
[FONT=arial]        Dim RDR As OleDb.OleDbDataReader = Comm.ExecuteReader[/FONT]
[FONT=arial]        RDR.Read()[/FONT]
[FONT=arial]        lblDef.Text = RDR.Item("Definition")[/FONT]
[FONT=arial]        Ansrs(0, r - 1) = RDR.Item("Answer")[/FONT]
[FONT=arial]        lblWeekNo2.Text = RDR.Item("WeekNumber")[/FONT]
[FONT=arial]        lblInfo.Visible = True[/FONT]
[FONT=arial]        lblInfo.Text = r & "/10"[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]    Private Sub FinishTest()[/FONT]
[FONT=arial]        lblInfo.Text = "You have successfully completed the test! Well done!"[/FONT]
[FONT=arial]        lblInfo.Left = (Me.Width / 1.5) - (lblInfo.Width / 1.5)[/FONT]
[FONT=arial]        ' When the test is done, it makes all of the things that the user won't need anymore, invisible[/FONT]
[FONT=arial]        lblDef.Visible = False[/FONT]
[FONT=arial]        lblWeekNo2.Visible = False[/FONT]
[FONT=arial]        btnNxt.Visible = False[/FONT]
[FONT=arial]        lblWeekNo.Visible = False[/FONT]
[FONT=arial]        txtAns.Visible = False[/FONT]
[FONT=arial]        lblAnswer.Visible = False[/FONT]
[FONT=arial]        lblDefinition.Visible = False[/FONT]
[FONT=arial]        TestScore()[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]    Private Sub TestScore()[/FONT]
[FONT=arial]        For r As Integer = 0 To 9[/FONT]
[FONT=arial]            MsgBox(Ansrs(0, r))[/FONT]
[FONT=arial]            If Ansrs(0, r).ToLower = Ansrs(1, r).ToLower Then[/FONT]
[FONT=arial]                Score = Score + 2[/FONT]
[FONT=arial]                MsgBox("You have scored " & Score)[/FONT]
[FONT=arial]            End If[/FONT]
[FONT=arial]        Next[/FONT]
[FONT=arial]    End Sub[/FONT]
[FONT=arial]End Class[/FONT][/SIZE]

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.
 
im doing this exact spelling test as my college coursework, and the one bit im struggling on Is the exact bit any help would be amazing
 
Back
Top