I’m a newbie and this is a simple problem I’ve been stuck on. How do I add numbers from an array in VB 2008?

I’ve filled the array with 10 test scores. I’ve sorted the array in descending order (from highest to lowest).

Now I need to figure out how to add the best 8 scores from my sorted array of 10 test scores.

Here is where I’m stuck so far, with my code:

Option Explicit On
Option Strict On
Module scores
    Sub Main()
        Dim name As String = ""
        Dim studentScoreString As String
        Const SIZE As Integer = 10
        Dim score(SIZE) As Integer
        Dim x As Integer
        Dim tempHolder As Integer
        Dim numberOfElements As Integer = 0
        Dim comparisons As Integer
        Dim totalScore As Integer
        Dim didSwap As Boolean
        Const QUIT As Integer = 999

        name = InputBox$("Please enter student's name: ")

        x = 0
        studentScoreString = InputBox$("Enter a score or " & _
                                       QUIT & " to quit ")
        score(x) = Convert.ToInt32(studentScoreString)
        x = x + 1
        Do While x < SIZE And score(x) <> QUIT
            studentScoreString = InputBox$("Enter a score or " _
                                           & QUIT & " to quit ")
            score(x) = Convert.ToInt32(studentScoreString)
            x = x + 1
        Loop
        numberOfElements = x
        comparisons = numberOfElements - 1

        didSwap = True
        Do While didSwap = True
            x = 0
            didSwap = False
            Do While x < comparisons
                If score(x) < score(x + 1) Then

                    tempHolder = score(x + 1)
                    score(x + 1) = score(x)
                    score(x) = tempHolder
                    didSwap = True
                End If
                x = x + 1
            Loop
            comparisons = comparisons - 1
        Loop

        ???? For x = 0 To 7
        totalScore = x + 1
        Next x


        System.Console.WriteLine("The cumulative points of the " _
                                 & "highest eight quiz scores for " _
                                 & name & " are " & totalScore)

        System.Console.ReadLine()

    End Sub

End Module

Thank you for any help!

See if this helps.

For x = 0 To 7
            If Not score(x) = Nothing Then totalScore += score(x) '// add to totalScore.
        Next

look at this code.....

Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim a() As Integer = {0, 1, 2, 3, 4}
        Dim b As Integer
        Dim i As Integer
        For i = 1 To 4
            b += a(i)
        Next
        TextBox1.Text = b


    End Sub
End Class

If ur problem is solved mark it read.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.