I want to write a program in VB, which takes a string from userthrough text box
ID: 3613101 • Letter: I
Question
I want to write a program in VB, which takes a string from userthrough text box and after clicking the count button the programcount the every individual alphabet and display in label or listbox that how many times it come in stringFor example:
string "hello world"
H comes 1 time in string.
E comes 1 time in string.
L comes 3 time in string.
O comes 2 time in string.
W comes 1 time in string.
R comes 1 time in string.
D comes 1 time in string.
I tried this many ways, but failed, please help me. Thanks.
Explanation / Answer
VB code:Dim vstring As Stringvstring$ =(txtMain.Text)frmMessage!lblMessage.Caption = "hello world " &CountCharacters(vstring$) & " characters in thisdocument"frmMessage. Public Function CountCharacters(Source$) As IntegerDimcounter%, t%Const Characters$ ="abcdefghijklmnopqrstuvwxyz" For t% = 1 To Len(Source$) I f InStr(Characters, LCase$(Mid$(Source$, t%, 1))) < >0 Then counter% = counter% + 1 End IfNext t%CountCharacters = counter%End Function. ITS HELPFUL TO YOU...... Public Function CountCharacters(Source$) As IntegerDimcounter%, t%Const Characters$ ="abcdefghijklmnopqrstuvwxyz" For t% = 1 To Len(Source$) I f InStr(Characters, LCase$(Mid$(Source$, t%, 1))) < >0 Then counter% = counter% + 1 End IfNext t%CountCharacters = counter%End Function. ITS HELPFUL TO YOU......
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.