Subject: Display highest test score
Posted By: kgs51 Post Date: 11/9/2004 1:02:09 PM
I have written this small vb.net program that a user can enter a test score and each time that they do, it displays the average test score and the number of test scores. I am confused though regarding the code to display the highest test score. Any help would be appreciated.

Reply By: katsarosj Reply Date: 11/9/2004 1:52:07 PM
Are you storing the results in a database?  If so you can use a Select statement to pull the highest value for the test scores.

Like:

SELECT Max([TestScore]) FROM [TableName]

Replace "TestScore" with the column name(without brackets) for your test scores.  Replace "TableName"(without brackets) with your table's name.

If you aren't using a database, please post some code and give a little more info.  It makes it easier for us to help you.

J
Reply By: kgs51 Reply Date: 11/9/2004 1:58:41 PM
No I am not. The user just enters a test score each time they press enter

Reply By: katsarosj Reply Date: 11/9/2004 3:23:49 PM
So how are you keeping track of the test scores?  Are you storing them in an array?

J
Reply By: kgs51 Reply Date: 11/9/2004 3:59:44 PM
Actually, I am doing a self study program and at this point I am not storing the scores anywhere yet.

Reply By: katsarosj Reply Date: 11/9/2004 4:55:03 PM
You said earlier that you were displaying average test scores and the number of test scores.  How are you keeping track of these test scores?

Can you post some code and list exactly what you want?  It is easier than me guessing each time.
Reply By: kgs51 Reply Date: 11/9/2004 5:53:01 PM
Operation
•    The user enters a test score ranging from 0 to 100 and then clicks the Enter score button or presses the Enter key to activate that button.
•    For each score, the application adds one to the number of scores, calculates the average score, and determines what the best score is so far. Then, it displays the results.
•    To clear the results so the user can enter another set of scores, the user clicks on the Reset button.

This is the project that I am working on. I have been able to do the code for the average score and number of scores.

Reply By: katsarosj Reply Date: 11/9/2004 7:03:35 PM
So I assume you are assigning these values to variables?  Adding the new test score to a current total and then dividing that by the total number of tests + 1 (the new test).

I guess one way to do it would be to create a new numeric variable and assign to it the first test's value.  Upon each submission you could compare the current test's value with the value stored in the variable.  If it is greater, it replaces the variable's value with it's own.

J
Reply By: kgs51 Reply Date: 11/9/2004 7:05:16 PM
Thank you very much for your input.

Reply By: kgs51 Reply Date: 11/9/2004 7:11:35 PM
That is exactly what I am doing. How would that part be coded. Can you give an example.

Thanks

Reply By: katsarosj Reply Date: 11/9/2004 10:56:01 PM
Declare the variable outside of your procedures:

-----------------------------------------------------------
Private intHighTestScore as Int32 'variable to hold the high test score
-----------------------------------------------------------

Then, inside your click event for the submit button after you calculate the current score, I am using a variable called intCurrentScore but you can substitute whatever you currently have:

-----------------------------------------------------------
'process code to get the current test score here and assign
'it to the variable intCurrentScore

If intCurrentScore > intHighTestScore Then
  intHighTestScore = intCurrentScore
End If
-----------------------------------------------------------

You could then use the variable to display the score in a label, textbox, etc.  The only problem is, once the application closes, you lose all of the information.  A better way would be to store this data somewhere - a text file, database, etc.

J
Reply By: kgs51 Reply Date: 11/10/2004 5:54:12 AM
Thank you

You have been a great help.

Reply By: katsarosj Reply Date: 11/10/2004 8:35:49 AM
No problem.

J
Reply By: kgs51 Reply Date: 11/19/2004 8:25:16 AM
With this accumulated data, how would I add these items to an array each time I add a new score.

Reply By: katsarosj Reply Date: 11/19/2004 9:46:06 AM
I don't think you need to add the high score and the average to an array since at any given time they are only going to equal a single number and you can store this in a single variable.

If you want to add other things, such as first name, lastname, score, etc., you can do something like this:

----------------------------------------
'declare these outside of any procedure
Structure Test
   Dim FirstName As String
   Dim LastName As String
   Dim TestScore As Byte
End Structure

Private Scores() As Test
Private intScoreCntr As Int32

---------------

'put this in your submit button click event
ReDim Preserve Scores(intScoreCntr)

Scores(intScoreCntr).FirstName = txtFName.Text
Scores(intScoreCntr).LastName = txtLName.Text
Scores(intScoreCntr).TestScore = txtScore.Text

txtFName.Text = ""
txtLName.Text = ""
txtScore.Text = ""

intScoreCntr += 1

----------------------------------------

Although this method will work, a much better way would be to store all of this information in a database.  
Reply By: kgs51 Reply Date: 11/19/2004 10:02:07 AM
Thanks again for your help

Ken


Go to topic 22383

Return to index page 711
Return to index page 710
Return to index page 709
Return to index page 708
Return to index page 707
Return to index page 706
Return to index page 705
Return to index page 704
Return to index page 703
Return to index page 702