Sorting scores from text file into an array

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • bnichole
    New Member
    • Apr 2014
    • 1

    Sorting scores from text file into an array

    I have a list of 30 scores ranging from 0 to 49 that I need to sort into an array.

    They need to be sorted as following:
    frequencies(0) = scores < 10
    frequencies(1) = scores >10 and <20
    frequencies(2) = scores >20 and <30
    frequencies(3) = scores >30 and <40
    frequencies(4) = scores >40 and <50

    so far, I have stored the text file into a temporary array and converted it to an integer (as follows)

    ***
    Code:
    Dim temp() as String = IO.File.ReadAllLines("Scores.txt")
    Dim Scores(30) as Integer
    Dim frequencies(4) as Integer
    
    'convert to string into integer
    For i as Integer = 0 To temp.Count - 1 
          scores(i) = CInt(temp(i))
    Next
    ***

    My question is, what steps do I need to take in order to store the correct scores from the text file into the frequencies array? Each score is stored on its own line in the text file.
    Last edited by Rabbit; Apr 28 '14, 10:13 PM. Reason: Please use [code] and [/code] tags when posting code or formatted data.
  • Luk3r
    Contributor
    • Jan 2014
    • 300

    #2
    You could just use something like this:
    Code:
            For Each itm In Scores
                If itm <= 10 Then
    
                ElseIf itm > 10 AndAlso itm <= 20 Then
    
                ElseIf itm > 20 AndAlso itm <= 30 Then
    
                ElseIf itm > 30 AndAlso itm <= 40 Then
    
                ElseIf itm > 40 AndAlso itm <= 49 Then
    
                End If
            Next

    Comment

    Working...