By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,853 Members | 2,246 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,853 IT Pros & Developers. It's quick & easy.

Sorting scores from text file into an array

P: 1
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)

***
Expand|Select|Wrap|Line Numbers
  1. Dim temp() as String = IO.File.ReadAllLines("Scores.txt")
  2. Dim Scores(30) as Integer
  3. Dim frequencies(4) as Integer
  4.  
  5. 'convert to string into integer
  6. For i as Integer = 0 To temp.Count - 1 
  7.       scores(i) = CInt(temp(i))
  8. 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.
Apr 28 '14 #1
Share this Question
Share on Google+
1 Reply


100+
P: 299
You could just use something like this:
Expand|Select|Wrap|Line Numbers
  1.         For Each itm In Scores
  2.             If itm <= 10 Then
  3.  
  4.             ElseIf itm > 10 AndAlso itm <= 20 Then
  5.  
  6.             ElseIf itm > 20 AndAlso itm <= 30 Then
  7.  
  8.             ElseIf itm > 30 AndAlso itm <= 40 Then
  9.  
  10.             ElseIf itm > 40 AndAlso itm <= 49 Then
  11.  
  12.             End If
  13.         Next
Apr 28 '14 #2

Post your reply

Sign in to post your reply or Sign up for a free account.