Skip to main content

Write a Vb.net program to accept sentences in text box and count the number of words and display the count in message box

· One min read
Kaustubh Kulkarni
file.vb
PublicClass Form1  
PrivateSub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim sentence AsString
Dim i AsInteger
Dim wc AsInteger
sentence = TextBox1.Text
Dim arr() AsChar = sentence.ToCharArray()
For i = 0 To arr.Length - 1
If arr(i) = " "Then
wc = wc + 1
EndIf
Next
MsgBox("Total Words "& wc + 1)
EndSub
EndClass