Computers & Internet Logo

Related Topics:

Anonymous Posted on Feb 27, 2008

Sentence can you help me to make my vb project run? my problem is "what code shall i use in displaying number of words as i enter a sentence" thank you..your code can help a lot to run my program.. god bless...

2 Answers

Anonymous

Level 1:

An expert who has achieved level 1.

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Mentor:

An expert who has written 3 tips or uploaded 2 video tips.

  • Contributor 51 Answers
  • Posted on Feb 27, 2008
Anonymous
Contributor
Level 1:

An expert who has achieved level 1.

All-Star:

An expert that got 10 achievements.

MVP:

An expert that got 5 achievements.

Mentor:

An expert who has written 3 tips or uploaded 2 video tips.

Joined: Feb 22, 2008
Answers
51
Questions
0
Helped
98015
Points
73

Assuming you define "word" as any string of non-whitespace characters bounded by a whitespace character (ie, space, tab, carriage return), or if in first position bounde donly rightwise and if in last position bounded only leftwise, then you would want to use the On_KeyUp event in the writing object in question (will assume it's a TextBox). I won't write the code for you but will provide pseudo-code:

private whitespaces, wordcount as Integer ' <--- Note: These are module-level vars


event_handler_begin

if [typed character is whitespace and wordcount = 0] then
wordcount = wordcount + 1
elseif [typed character is whitespace and wordcount > 0] then
if [whitespaces > 0 then]
wordcount = wordcount + 1
whitespaces = 0
else
whitespaces = 1
end if
end if

event_handler_end

COMMENTS: Notice that if a typed char is not a whitespace we don't care much about it. The whitespace is defining the word-count, not the actual words themselves. The approach to take with stuff like this is not to think of the problem the way a human naturally does (ie, we count words we see on a piece of paper or screen and say what we saw), but to ask, "How is 'word' defined?", then based on that definition, ask how you can spot when a differentiation between words is detectable at any given time in the history of the object's state. In this case it is known by the entering of whitespace chars and their relation to one another, so that is what we are concerned with.

One thing this code above does not do is handle the terminal case, for example, if I type:

"All good people turn their heads each day"

in a textbox, the count would be 7, since I am not catching the termination point of the word "day". If I had typed "All good people turn their heads each day ", then I would have gotten a count of 8. Also, if I type ". . ." have I just entered 3 words? No, of course not, but the code above would say so (as long as I handled the terminal case; see below).

So what you must also handle for is the terminal case and the only way to know it has been reached is to add a count value when the user indicates he or she is done typing, most likely by clicking off the box (use the object's lost focus event). If the application you are building though is keeping the word count limited, then when a user enters a whitespace and causes the count to go above a certain number, then you cancel the key event and revert the text. This requires more coding as well, and use of the previous value property of the object, for example, or use of string functions like Left() applied to the text in the text entry object you are using. Another thing is that this code does not handle deletes and backspaces; what happens when I hit backspace or select and delete a word of set of words? Now things have gotten really fun.

As you can see, this is not as easy as it first looks, as with all event-oriented, user-centric programming. The matter of keeping track of the state of the application and its data (both on-screen and in databases) is always more complicated than it first appears and so it is better to come up with a state-management strategy ahead of time. Just be prepared to have that strategy become either useless or make exceptions to it, as in an app of any size, the chances of that happening are about 99.9999%. There is also making sure your definitions for things like "word" are accurate to the purpose at hand; in some cases, you might want a string like " . " to be considered a 'word' and at other times, not. The devil is in the details.

Having said that an I am certain thoroughly discouraged you, all i can say is, Good Luck!

A

Anonymous

Send me your code -- and I can fix it

Ad

Add Your Answer

×

Uploading: 0%

my-video-file.mp4

Complete. Click "Add" to insert your video. Add

×

Loading...
Loading...

Related Questions:

0helpful
1answer

I need a radoi code for my 2002 Mercedes CLK 430

Please check the information that came along with the owner's manual. It should be printed on a card that comes with those booklets. I assume you've already done that though. I've attached the procedure for entering the code below. Let me know if you have any trouble with it.

If the radio is disconnected from the power supply it is not ready for operation when reconnected. After switching on the ignition and the radio the word "CODE" appears on the display and the letter "C" flashes.

NOTE: The five-digit code number for this radio is printed on the CODE CARD which you were given.

Enter the code number with station buttons, e.g. number 1, station button 1.

After entering the first digit the word "CODE" disappears and the digit entered is displayed followed by 4 dashes. The next digit to be entered flashes. After all 5 digits are entered, the first digit flashes again. In this state the code number can be written over repeatedly. A correction can be made only by reentering the entire code number.
Confirming the code number: Press seek-UP/seek-DOWN or SCAN button. The radio switches on automatically and displays the station or frequency stored for station button 1.

If the wrong code number has been entered and confirmed, the word "CODE" appears on the display again. After the code has been entered three times incorrectly the word "WAIT" appears on the display and the radio is disabled for approx. 10 min .

NOTE: The waiting time continues to run only when the radio is switched on.

After expiration of the waiting time the word "CODE" appears on the display again and the correct code number can be entered. After 3 more incorrect entries the radio is again disabled for 10 min . After 3 more incorrect entries (a total of 9 incorrect entries) the waiting time is increased to 60 min . After 3 more incorrect entries the radio locks up again for 60 min .

Certified Auto Service Repair for Audi BMW Greensboro Jaguar Land Rover...
tip

How to Open a Password Protected Word 2003 Document?

Microsoft Word document offer password protection which allows you to protect your sensitive information containing in your Word file, then anyone who wish to access to your file should enter the correct alpha-numeric password firstly. If you cannot open a secured word 2003 document, it must be irritating, right? This article will show you three effective options to <a href="http://recoverlostpassword.com/products/wordpasswordrecovery.html"><u>open a password protected word 2003 document</u></a>.<br /> <br /> <img src="open-password-protected-word-document.jpg" /><br /> <b><br /> <br /> Method 1: Using VB.NET<br /> </b><br /> <br /> The following code sample shows how to open a password protected word document using VB.NET<br /> <br /> [VB.NET CODE STARTS]<br /> Dim objWord As Object<br /> Dim strPassword as string = "PASSWORD"<br /> <br /> objWord = CreateObject("Word.Application")<br /> objWord.visible = False<br /> objWord.application.WindowState = 2<br /> objWord.application.DisplayAlerts = False<br /> <br /> Try<br /> objWord.Documents.Open("YOUR DOCUMENT FULL PATH NAME", PasswordDocument:=strPassword )<br /> Catch ex As Exception<br /> Msgbox ("Cannot open word document" ,vbExclamation , "Password Protected")<br /> End Try<br /> [VB.NET CODE ENDS]<br /> <br /> <br /> <b>Method 2: Obtain the password from the source</b><br /> <br /> <br /> The following steps sample shows how to obtain the password from the source<br /> Step 1: Check with the word document source for the password.<br /> Ask yourself where does the locked word 2003 document come from? Supposing it created by someone else, then ask the creator for the password. If your own are the word document source, you will need to locate the lost password.<br /> Step 2: Verify the password with the source.<br /> Make sure you have the right password on hand. Verify the password can save you time. The other reason to do so is that you never know they might have given you the wrong password in the first place.<br /> Step 3: Enter the correct password.<br /> Type in the correct password at the "Enter Password To Open File" dialog box. After you have entered the password, click the OK button.<br /> <br /> <b><br /> Method 3: Using password-cracking software</b><br /> <br /> <br /> If so far you still didn't solve your problem, then you'll have to go buy one of password-cracking software available for this purpose. So go to the link in "Source(s)" and download the <a href="http://www.recoverlostpassword.com/products/wordpasswordrecovery.html">word password cracker</a> program. It comes with a trial version and follows the walk through. You only need to use the program to open the locked word document, choose the type of attacks for word document with strong encryption. Then the program will start and keep running until find out the lost word password for you to open.<br /> Source(s):Good Search: <a href="http://recoverlostpassword.com/products/wordpasswordrecovery.html">SmartKey Word Password Recovery<br /> </a><br /> <br /> Keep in mind that there nothing will miss as long as you use the corresponding password to<a href="http://recoverlostpassword.com/products/wordpasswordrecovery.html"> <u>open your password protected word document</u></a>. <br /> <br /> Article Source:<a href="http://recoverlostpassword.com/article/open-password-protected-word-2003-document.html">http://www.recoverlostpassword.com/article/open-password-protected-word-2003-document.html</a> <br />
on Apr 15, 2011 • Computers & Internet
7helpful
1answer

Problem with entering anti-theft radio code for Honda Fit: The radio screen says: "Enter Code:" I enter the confirmed correct code, but when doing so when the actual code (all numbers) turn into letters or...

when you use the "preset keys" (the keys on the radio with numbers on them) to enter the code, each time you press a code number, a letter appears [c, o, d, e]. once the word is spelled out, from entering the correct 5 digits, the radio is reset, ready to go.

BUT if you miss a number, enter a wrong number, whatever, each number pressed, still makes a letter appear from the word "code". once the word is spelled out, by entering ANY 5 numbers, if ANY of the 5 is wrong, the radio displays a message "Error" and then a number 1 thru 10.

When you see the word "Error..."

the next preset button you push, starts the whole thing over again. The radio says "Enter code". That is when you enter the 1st of the 5 digits, the letter C appears, enter the next digit, the letter O appears, enter the next digit, the letter D appears, enter the last digit, the letter E apperas, the radio is reset, ready to go, if you got the 5 correct numbers entered.

you have 10 chances to enter the right 5 digit code. Each wrong try of 5 digits yeilds a display of "Error 1", "Error 2", "Error 3", etc 'till you get to 10 incorrect tries of 5 digits each.

If you dont get it right in 10 tries, you have to leave the radio "on" for an hour, then it will let you start the 10 tries over again.

Good luck!
0helpful
2answers

Source code for word count

Haha, i wrote one of thee a while ago for a competition. You need to us e the char at function mate :D
Inside a for loop
Ill havea look for you though :D
0helpful
1answer

Formatting/Rounding number

forget its not your cup of tea
0helpful
1answer

Stand alone vb programme

yaa you can use the Setup Wizard from your VB for your project. It will make a setup for your project and will put all the runtime required files in a same folder, with your project executable with a setup.exe file. Copy all these files in any device like CD,DVD, Flash memo etc, in a same folder. And run this setup on any computer to which you want to install it.

Then your project will run on that computer.


Thanks
Iqbal
0helpful
1answer

Program

Sub aa()
'
' aa Macro
'
'
Dim a As String
a = "how are you this is dharani"
Dim leng, cnt As Integer
leng = 1
cnt = 0
While leng <= Len(RTrim(a))
If Mid(a, leng, 1) = " " Then
cnt = cnt + 1
End If
leng = leng + 1
Wend
If Len(RTrim(a)) > 0 Then
cnt = cnt + 1
End If
MsgBox Str(cnt) + " Words"
End Sub
0helpful
2answers

Visual basic 6.0

Use a compare (instr) command to search the sentence for punctution and spaces. Increment a variable for each word found, resetting the search string and retaining the start position of each find.
0helpful
2answers

Help me

this the code for your problem. by the way this for vb6.0

Sub CountCharacters(Text As String)
Dim iVowel As Integer
Dim iCons As Integer
Dim iNum As Integer
Dim iSpace As Integer
Dim iOther As Integer

Dim cnt As Integer
Dim sChar As String

For cnt = 1 To Len(Text)
sChar = LCase(Mid(Text, cnt, 1))

Select Case sChar
Case "a", "e", "i", "o", "u" ' And sometimes "y"?
' Vowel
iVowel = iVowel + 1
Case "a" To "z"
' Includes the first case, but VB matches the first case and stops
iCons = iCons + 1
Case "0" To "9"
' Numbers
iNum = iNum + 1
Case " ", vbTab, vbLf
' Space characters
' Not including vbCr as this will likely be dealing with Windows text
' and I only want to match one character for a newline
iSpace = iSpace + 1
Case Else
If sChar <> vbCr Then iOther = iOther + 1
End Select
Next cnt

Debug.Print "Text: " & Text
Debug.Print "Vowels: " & CStr(iVowel)
Debug.Print "Consonants: " & CStr(iCons)
Debug.Print "Numbers: " & CStr(iNum)
Debug.Print "Space characters: " & CStr(iSpace)
Debug.Print "Other: " & CStr(iOther)
End Sub
Not finding what you are looking for?

127 views

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Grand Canyon Tech
Grand Canyon Tech

Level 3 Expert

3867 Answers

Brad Brown

Level 3 Expert

19187 Answers

Cindy Wells

Level 3 Expert

6688 Answers

Are you a Computer and Internet Expert? Answer questions, earn points and help others

Answer questions

Manuals & User Guides

Loading...