calculating sum, average, highest and lowest grades

Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 4
Reputation: lab3tech is an unknown quantity at this point 
Solved Threads: 0
lab3tech lab3tech is offline Offline
Newbie Poster

calculating sum, average, highest and lowest grades

 
0
  #1
Nov 25th, 2006
I am new to VB, and am having problems with a program. I have a textbox where the user enters a grade value, then clicks tghe add button to display the grade in a listbox. The user continues the entries until all grades have been entered. I have also programmed a remove button so that the user could select a grade int he listbox and then click the remove button to delete it from the list. When the user clicks the calculate button, I determine the total number of entries (listgrades.item.count); this value is returned correctly. I then try to copy the contents of the listbox into an array as I thought that would be the best way to determine the highest, lowest, and sum of all the grades. I would then use the sum/total to get an average. I then need to assign a letter grade to each numeric grade and display the total number of grades in each category. I obviously am not doing this correctly, as the strallgrades has a zero value.
My code is below - any assistance would be appreciated!!

'to count the number of items in the listbox
total = LstGrades.Items.Count
Dim curindex As Integer
Dim strallgrades() As String
Dim intCounter As Integer
LstGrades.Items.Add(" ")
For intCounter = 0 To UBound(strgrade)
strallgrades(intCounter) = LstGrades.Items.Item(intCounter)
Next
For curindex = 0 To UBound(strgrade)
Debug.WriteLine(strgrade(curindex))
Next
Array.Sort(strgrade)
Array.Reverse(strgrade)
For curindex = 0 To UBound(strgrade)
Debug.WriteLine(strgrade(curindex))
Next
LblSum.Text = total
 End Sub

Last edited by ~s.o.s~; Nov 26th, 2006 at 1:33 am. Reason: Fixed code tags.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,114
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 281
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: calculating sum, average, highest and lowest grades

 
0
  #2
Nov 26th, 2006
First of all, did you color the code yourself? If so, please don't. Using code tags properly will color it for you. it's [code=vb] (no spaces) at the beginning, and at the end of the code [/code]. Also, indenting your code would help a lot, too.

I can't figure out how your question and the code is related. You mention
Originally Posted by lab3tech View Post
When the user clicks the calculate button, I determine the total number of entries (listgrades.item.count); this value is returned correctly. I then try to copy the contents of the listbox into an array as I thought that would be the best way to determine the highest, lowest, and sum of all the grades.
Why are you defining strallgrades as a string if you want to find the lowest, highest, and sum? Wouldn't integers be more appropriate?

Originally Posted by lab3tech View Post
I would then use the sum/total to get an average.
Where is sum calculated? I expected to see a + somewhere in the code used to add the values together.

Update the code to add the grades together and see how that works. mIf it does, try calculating the average. If it doesn't, post again and we can tweak your attempt.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC