CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 1999
    Posts
    58

    Help counting words in a textbox



    Hi,

    I'm trying to count the number of words in a textbox. I use the following code. But when I press the space bar twice, my word count is wrong because it's counting the space as a word. Can you please help me.


    Dim oneChar As String

    Dim i As Integer

    Dim x As Integer

    Dim howlong As Integer

    howlong = Len(txtMaintext.Text) ' Parse through the characters in the string

    For i = 1 To howlong

    oneChar = Mid$(txtMaintext.Text, i, 1) ' Get a character

    If oneChar = " " Then x = x + 1

    txtNumWords.Text = x + 1 'This is the words count in the textbox

    Next

  2. #2
    Join Date
    May 1999
    Posts
    45

    Re: Help counting words in a textbox



    When you encounter a space. Run a while loop to ignore whitespaces.



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured