Hi there...

I'm looking for words counter code

I build the form which contain textbox and botton

and I'm stopped at the code, I just did the code that count the space between each word

but I think it stills need more things to add

and if you have any ways to build this project

reply me

and I'm here to look for your help

please reply soon...

Recommended Answers

All 11 Replies

I don't have .NET, so I'll give you the breakdown of what I would do. There is a command, called "split" that allows you to rip a string apart, by a certain delimiter (character). It Returns an array. What I would do is split the string by space, and then test how many elements of the array there are. That may not tell you how many words, but it will certainly tell you how many parts of a string there is seperated by a space :)

thanks Comatose for your advise

i try to do what you suggest but it still not working

I have .net and VB 6 so i would like to give me your code

if you can..

Alright, here is the VB6 Equivelant code for what you want to do. The same concept will apply in .NET, but I know that the syntax is different. I'll research the same code on google, and post the code for doing this in .NET.

Mkay, Here is the similar VB.NET Code, To split a string, and grab it's ubound of the return array:

Dim parts() As String
parts = TextBox1.Text.Split(" ")
WordCount = parts.GetUpperBound(0) ' /* I don't know if this need a + 1 or not */

thank you very mach Comatose for your help

the first code was smiller what did before. it just count the speces . but if you put many spaces in the textbox the counter will count it !!

i don't know if there is way to avoid count two or more spaces if they are togather.

and about the second code is not working with me, maybe i have to change the variable ... will try it and will post to you..


thanks...

I don't really like VB.NET, so the code is in VB6

Function WordCounter(words) As Integer

	Dim strTemp As String
	Dim counter As Integer
	strTemp = Split(words, " ")
	counter = UBound(strTemp)
	
	For i = 0 To counter
		If strTemp(i) = "" Then
			counter = counter - 1
		End If
	Next i
	
	WordCounter = counter + 1

End Function

No one in this thread likes VB.NET it seems :)
(Sorry, just making an unconstructive observation)

As Far As I'm Concerned, .NET is the Bane of Windows Programming. I'd Rather Write An Entire App For Windows in ASM :eek:

LuckyMan- you may want to check out "Regular Expressions" on msdn or even Google; it is native to VB .NET (and Pearl, etc) and has powerful string parsing functions that, I hope, will make everything much easier.

Hi THERE

Try this code but firt create a label and a textbox and command button lol

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String


str = TextBox1.Text

str = Trim(str)
Do While InStr(1, str, " ")
str = Replace(str, " ", " ")
Loop
Dim aWords
aWords = Split(str, " ")
Label1.Text = ("There are " & UBound(aWords) + 1 & " words in " & "(" & str & ")")

end sub

Try this code ^_^

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim str As String


str = TextBox1.Text

str = Trim(str)
Do While InStr(1, str, " ")
str = Replace(str, " ", " ")
Loop
Dim aWords
aWords = Split(str, " ")
Label1.Text = ("There are " & UBound(aWords) + 1 & " words in " & "(" & str & ")")
end sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.