Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact


Displaying/Calculating the score in a test.


Displaying/Calculating the score in a test.

Author
Message
Yhym
Yhym
Supreme Being
Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)Supreme Being (241 reputation)

Group: Forum Members
Posts: 1, Visits: 2
Hi, I've got a problem with my spelling program where I can't display the correct score at the end of the test. Well, I can't actually display the score at all... Instead, it just displays the actual answers which is not what I want.

Btw. I'm using Access to store all the data if you wonder.

This is the code that I've so far:







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







Thanks in advance and I hope that somebody will be able to help me!
Joey
Joey
Forum God
Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)Forum God (9.3K reputation)

Group: Forum Members
Posts: 72, Visits: 46
The line that is supposed to display the score is,



MsgBox("You have scored " & Score)



This line is inside the For..Next loop, therefore it will execute for each answer. Are you looking to display the score after each answer or are you looking for the final score for the entire test? If you're looking for the final score you would need to take the above code outside the For..Next loop.
GO


Similar Topics


Reading This Topic


Login
Existing Account
Email Address:


Password:


Social Logins

Select a Forum....

















A1VBCode Forums


Search