I am writing a program that takes a group of integers from a text file. There are 20 or them all between 0-9. I am trying to display the frequency of each digit in a list box. I thought I had the code correct but for some reason it’s off by one. Also I am drawing a blank when it comes to displaying the order of the numbers in the text file but only displaying each number once. My current code is listed down below. Any help would be awesome. Thanks
Code:
Public Class Form1 Private Numbers(10) As Integer Private number As Integer Private UpperBound As Integer Private Sub btnDisplay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisplay.Click Dim sr As IO.StreamReader = IO.File.OpenText("Num.txt") For i As Integer = 0 To 20 number = CInt(sr.ReadLine) Numbers(CInt(number)) += 1 Next sr.Close() For i As Integer = 0 To 9 lstDisplay.Items.Add(Numbers(i)) Next End Sub
Comment