| | |
calculating sum, average, highest and lowest grades
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Nov 2006
Posts: 4
Reputation:
Solved Threads: 0
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!!
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.
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
Why are you defining strallgrades as a string if you want to find the lowest, highest, and sum? Wouldn't integers be more appropriate?
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.
I can't figure out how your question and the code is related. You mention
•
•
•
•
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.
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
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- factorial using a for loop (C++)
- Finding the lowest of five test scores (C++)
- C++ Errors Pls Help!! (C++)
- Please help me (C++)
- Help me please! (Java)
- Only first out of three calculations is wrong (C++)
- c++ arrays, help identify element place (C++)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Communicating between PCs
- Next Thread: Project Problem
| Thread Tools | Search this Thread |
* 6 429 2007 access activex add age application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine tags textbox time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






