I am trying to write a program that reads in a text file and prints out how many # of each letter shows up for example if my text files is "Good food"

there will be 2- d, 1- f, 1 -g, 4- 0.

The problem that I am having when I run through the loops is that the spaces are counting for A. so in the cause of "Good Food"
there will be 2- d, 1- f, 1 -g, 4- 0 and 1 - A.

Here is my sub with the loop.

Private Sub btnsubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsubmit.Click
 Dim i, j, k, l, x As Integer
    Dim lettercount(26) As Integer
    Dim digramCount(26, 26) As Integer
    Dim letterArray(26) As Label
        Dim objReader As New StreamReader("test.txt")
        Dim sLine As String = ""
        Dim arrText As New ArrayList()

            sLine = objReader.ReadLine()
            If Not sLine Is Nothing Then
            End If
        Loop Until sLine Is Nothing

        For Each sLine In arrText

            For j = 0 To lettercount.Length - 1
                lettercount(j) = 0

            For k = 0 To 25
                For l = 0 To 25
                    digramCount(k, l) = 0

            For i = 1 To sLine.Length
                Dim int As Integer
                int = selectletterCase(sLine.Substring(i - 1, 1))
                lettercount(int) += 1

            For x = 0 To 25
                letterArray(x).Text = lettercount(x).ToString
        End If
    End Sub

any help is appreciated!

I realized that ith as something to do with my select case function. If there is either a space or a character such as (. , / ? -) it will send it to the case and return a 0 by deafult because there is not a case for the characters. my problem is that "a" returns the value 0 and when either a space or character is sent to the select case function its + 1 to the total # of A's in the string

This article has been dead for over six months. Start a new discussion instead.