Counting characters of multiple words in a text box.

pewlat

New member
Local time
Today, 09:00
Joined
Sep 30, 2013
Messages
4
Hey guys!

As the title describes, I'm trying to calculate the characters of each single word I've written in a text box.

Example:

"I've been trying to solve this shit for hours."

Now I want a buttonclick() to calculate: 1w: 4 chars - 2w: 4 chars 3w: 6 chars etc..

My task is to find how many words in this sentence containing more than 6 characters (I know this example doesn't contain more than 6 tho) - Hope you get the picture!

Thanks in advance.
 
Hey there, check out the VBA.Split() function, which breaks up a string into an array at a delimiter that you specify. Then you can enumerate the members of the array, and Bob's yer uncle.
 
Hey there, check out the VBA.Split() function, which breaks up a string into an array at a delimiter that you specify. Then you can enumerate the members of the array, and Bob's yer uncle.

Thanks for the quick reply.

Hm, I've got this one for calculating the total words in a text box:

Dim sWords() As String

sWords = Split(txtInput, " ")
numsentence = 0
If Len(txtInput) = 0 Then
Exit Sub
Else
numsentence = 1
End If

txtOutput = "Amount of Words are: " & UBound(sWords)

Is there any way to use this one for calculating the characters aswell?
 
Last edited:
How does that calculate total words? To count the elements in an array you can use the UBound function, which returns the upper bound, to which you'd add 1. To determine the length of a string, use the Len() function, which appears in that code you posted.
 
How does that calculate total words? To count the elements in an array you can use the UBound function, which returns the upper bound, to which you'd add 1. To determine the length of a string, use the Len() function, which appears in that code you posted.


Yeah, forgot "txtOutput = "Antall ord er(M): " & UBound(sWords)"
 
Yeah, and so probably . . .
Code:
UBound(sWords) + 1
. . . because arrays are indexed starting at zero, so the UBound() of an array with a single element is zero.
 

Users who are viewing this thread

Back
Top Bottom