5
Contributors
6
Replies
8
Views
5 Years
Discussion Span
Last Post by dnk
Featured Replies
  • 2

    i think to count space cause every word will separated with space. [CODE] Private Sub Command1_Click() Dim Counts As Integer If Text1.Text = "" Then Counts = 0 Else Counts = 1 For i = 1 To Len(Text1.Text) If Then 'this part i don't know how to search the space … Read More

  • 1

    Use Mid function to search space in text box: [CODE]Private Sub Command1_Click() Dim Counts As Integer If Text1.Text = "" Then Counts = 0 Else Counts = 1 For i = 1 To Len(Text1.Text) If Mid(Text1.Text, i, 1) = " " Then ' use Mid to search space Counts = … Read More

  • By this below codes you can check how many words are there on single line or multi line text box even if user enter space in between and before or after words. [CODE] Private Sub Command1_Click() Dim Counts As Integer Dim dupText As String dupText = Replace(Trim(Text1.Text), vbNewLine, " ") … Read More

2

i think to count space cause every word will separated with space.

Private Sub Command1_Click()
Dim Counts As Integer
If Text1.Text = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(Text1.Text)
        If Then 'this part i don't know how to search the space
            Counts = Counts + 1
        End If
    Next
End If
MsgBox Counts
End Sub
1

Use Mid function to search space in text box:

Private Sub Command1_Click()
Dim Counts As Integer
If Text1.Text = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(Text1.Text)
        If Mid(Text1.Text, i, 1) = " " Then ' use Mid to search space
            Counts = Counts + 1
        End If
    Next
End If
MsgBox Counts
End Sub

Edited by Jx_Man: n/a

Comments
Usefull
Thanks for Mid function
Why do you insist on doing their homework?
0

What if there are 2 or more spaces between some words?
Did you count the first word? It has no space in front of it.
Did you consider the way many people now incorrectly write? They never add a space after a sentence -- just run the 2 sentences together.

Things to think about.

1

By this below codes you can check how many words are there on single line or multi line text box even if user enter space in between and before or after words.

Private Sub Command1_Click()
Dim Counts As Integer
Dim dupText As String

dupText = Replace(Trim(Text1.Text), vbNewLine, " ")

If dupText = "" Then
    Counts = 0
Else
    Counts = 1
    For i = 1 To Len(dupText)
        If Mid(dupText, i, 1) = " " Then ' use Mid to search space
            If Mid(dupText, i - 1, 1) <> " " Then
                Counts = Counts + 1
            End If
        End If
    Next
End If
MsgBox Counts
End Sub
Comments
and thanks for doing his homework for him. Now he doesn't have to think.
Thanks for duplicate checking :)
agree
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.