Question about Computers & Internet

2 Answers

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...

Posted by on

2 Answers

  • 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

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!

Posted on Feb 27, 2008

Send me your code -- and I can fix it

Posted on Feb 27, 2008


1 Suggested Answer

6ya6ya
  • 2 Answers

SOURCE: I have freestanding Series 8 dishwasher. Lately during the filling cycle water hammer is occurring. How can this be resolved

Hi,
a 6ya expert can help you resolve that issue over the phone in a minute or two.
best thing about this new service is that you are never placed on hold and get to talk to real repairmen in the US.
the service is completely free and covers almost anything you can think of (from cars to computers, handyman, and even drones).
click here to download the app (for users in the US for now) and get all the help you need.
goodluck!

Posted on Jan 02, 2017

Add Your Answer

Uploading: 0%

my-video-file.mp4

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

×

Loading...
Loading...

Related Questions:

1 Answer

I had a new battery installed recently. Of course this requires the code to be reentered for the radio to function. We guessed at what we thought it was & after the 3rd try OFF displayed where the word...


suggest that you call dealer, they can assist, have the vehicles vin# look on your cars registration on on driver side front of window ,or windsheild. have that number handy because they will ask, and they will also ask for personal info.in which you purchased the vehicle from, such as dealership,and their name, phone number,address,state,zip code, and possibly phone number. due to identity theft,be patient,ask questions! these codes are free to customers! do not take i don't know for answer! if you have to fax info.-do it. just make sure you look the dealers number up,then do it. do not be a victim,try to do it over a home phone,not cell. just trying to not let you be a victim ok? glory to him. you know the rest. be safe be secure, ask,ask ask, you will get your answer there is a reason for everything,all we have to do is ask and it shall be delivered!

Dec 31, 2010 | 2000 Mitsubishi Galant

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

1 Answer

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!

Apr 26, 2009 | 2007 Honda Fit Sport Hatchback

2 Answers

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

Sep 09, 2008 | ArcMedia JavaScript Source Code 3000 Pro...

1 Answer

Formatting/Rounding number


forget its not your cup of tea

Jul 31, 2008 | Computers & Internet

1 Answer

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

Mar 31, 2008 | Computers & Internet

1 Answer

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

Feb 27, 2008 | Computers & Internet

2 Answers

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.

Feb 27, 2008 | Computers & Internet

2 Answers

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

Feb 21, 2008 | Computers & Internet

Not finding what you are looking for?
Computers & Internet Logo

Related Topics:

103 people viewed this question

Ask a Question

Usually answered in minutes!

Top Computers & Internet Experts

Les Dickinson
Les Dickinson

Level 3 Expert

18385 Answers

kakima

Level 3 Expert

102366 Answers

David Payne
David Payne

Level 3 Expert

14161 Answers

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

Answer questions

Manuals & User Guides

Loading...