Visual Basic Development Bookmark and Share   
 Home > Visual Basic Language > counting letter
 

counting letter

How to count letter from input text file?I've done for counting letter from textbox:
Text = txtText.Text
txtText.SetFocus
For I = 1 To Len(Text)
Aschii = Asc(UCase$(Mid$(Text, I, 1)))
Select Case Aschii
Case vbKeyA To vbKeyZ
LetterCount(Aschii) = LetterCount(Aschii) + 1
Percent(Aschii) = LetterCount(Aschii) / Len(Text) * 100


Case Else
End Select
Next I

For I = vbKeyA To vbKeyZ
lstResult.AddItem Chr$(I) & vbTab & LetterCount(I) & vbTab & Percent(I)
Next I

============================================
Now my question is how to count letter of occurence from input text file? Anyone can help me on this?thanks~
deehanie  Friday, March 03, 2006 2:22 PM

Private Function GetLineCount(ByVal sPath As String) As Integer

Dim sr As StreamReader = File.OpenText(sPath)

Dim LineText As String

Dim iLineCount As Integer

LineText = sr.ReadLine()

iLineCount = 1

While Not LineText Is Nothing

For I = 1 To Len(LineText)
Aschii = Asc(UCase$(Mid$(LineText, I, 1)))
Select Case Aschii
Case vbKeyA To vbKeyZ
LetterCount(Aschii) = LetterCount(Aschii) + 1
Percent(Aschii) = LetterCount(Aschii) / Len(LineText) * 100


Case Else
End Select
Next I

For I = vbKeyA To vbKeyZ
lstResult.AddItem Chr$(I) & vbTab & LetterCount(I) & vbTab & Percent(I)
Next I

LineText = sr.ReadLine()

iLineCount += 1

End While

sr.Close()

Return iLineCount

End Function

DMan1  Friday, March 03, 2006 2:48 PM

Private Function GetLineCount(ByVal sPath As String) As Integer

Dim sr As StreamReader = File.OpenText(sPath)

Dim LineText As String

Dim iLineCount As Integer

LineText = sr.ReadLine()

iLineCount = 1

While Not LineText Is Nothing

For I = 1 To Len(LineText)
Aschii = Asc(UCase$(Mid$(LineText, I, 1)))
Select Case Aschii
Case vbKeyA To vbKeyZ
LetterCount(Aschii) = LetterCount(Aschii) + 1
Percent(Aschii) = LetterCount(Aschii) / Len(LineText) * 100


Case Else
End Select
Next I

For I = vbKeyA To vbKeyZ
lstResult.AddItem Chr$(I) & vbTab & LetterCount(I) & vbTab & Percent(I)
Next I

LineText = sr.ReadLine()

iLineCount += 1

End While

sr.Close()

Return iLineCount

End Function

DMan1  Friday, March 03, 2006 2:48 PM

You can use google to search for other answers

Custom Search

More Threads

• vb script remove text leave columns and data for input to db
• VB 2008 Express eddition - EXE File Problem
• Event handling, and multiple Handlers
• Can I fill many images in one picturebox?
• webbrowser control documentcomplete event not firing when iframe does not load.
• correct method for resize
• It takes so long to verify before installing a VB published program!
• Server and Client Communication
• Returning reference not in prototype
• Error updating Exchange via web dav from vb