我正在尝试实现一个程序,该程序可以在您键入时计算多行文本框中的单词。我可以让它计算单词,直到我按下“enter”键并输入一个单词。它不承认这一点。这是我的代码:
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles TextBox1.TextChanged
Dim str As String
Dim i, l, words As Integer
str = TextBox1.Text
str = LTrim(str) 'removes blank spaces at the beginning of text
str = RTrim(str) ' removes blank spaces at the end of text
l = str.Length
i = 0
words = 0
While (i < l)
If str(i) = " " Then
words = words + 1
i = i + 1
While str(i) = " " ' removes more than 1 blank space
i = i + 1
End While
Else
i = i + 1
End If
End While
words = words + 1 ' adds the last word
TextBox2.Text = ("" & words)
End Sub