Hi guys, i am making a typing speed checker software in vb6. Program is showing words attempted, mistake %age and net speed. I need help to get print of the words attempted with mistakes shown underlined/bold in printing. Please help me on the way. (project is attached, please extract it on C:\Speed Master).
Thanks in advance.
Kinda difficult to do what you are asking (IMHO) .
Let's say, for example an extra space or an extra single character (with a space on either side), then when you attempt to see if ONE word was messed up, you might even have 2, 3 or 4.. I guess you could go through your first textbox, by word, and see if it appeared in the second textbox 'somewhere close to where it was supposed to be', and then if it isn't found, then you could highlight/underline that word in the upper listbox...however, if you were to do that, and looking for the word "polymath" and the typiest had typed in "Tagore was a Bengali p polymath o who reshaped", then you WOULD find 'polymath' but then you would have to some how account for the 'p' and 'o' (in this example). Sounds TO ME, very, very complicated.
PS---I changed some of your code (expecially the hard-coded paths...you should (almost) NEVER type in a hard-coded path. If necessary, you can set global variables to represent that path, and then instead of changing the actual path everywhere it occurs, you would be able to change it in only one place. I also set your created-combobox listindex to 0 so it would show something when the form comes up, instead of wasting a user's time HAVING to pick an item...at least one item is already picked for him/her.
I also commented out your ON ERROR line....at least for testing, I'd advise not to use it....if you feel you MUST add it in when your program is completely finished and ready for deployment, then by all means, add it back (just in case your testing didn't find all potential errors, it is better for an app to not work correctly than for it to crash (IMO).
Sam
I would say never use On Error Resume Next as a solution for errors. It is better to have a program crash than to have one continuing on like everything is fine while your data is being trampled on by errors. It is good to use an error handler to catch errors and either take action to correct the errors or notify the user.
Any need for On Error Resume Next [except for cases where you check err.number after the very next line and take action] shows poor programming.
As for checking the words typed, I haven't looked at the project [have no intention of downloading it without at least seeing some code posted and some specific questions asked] I would think using split() to break the text into an array of words and then compare the elements of the arrays would be a good start if it isn't done already.
DM-it's a bit more complicated that that (IMO)....he has not done a bad job in general in setting this up, but what he is asking might not be what I'd do.
First, he has NO code for the button that he wants to use to display the 'missed' words.
But this is what he has (in general).
One textbox that contains text stored in an rtf document. As a user types (or attempts to type) the same words in a second textbox, each word in the first box is highlighted (font color change). Then as he attempts to type in the next word, he is 'prompted' by the next word which now becomes the new color. All is well and good until an error is made. If it is only a misspelling, no problem, but if a SPACE is added, then the next word is automatically highlighted, so when the typist tries a NEW word , he will be one word behind. This is a cumulative affect because of spaces. So, when one gets all done, and errors (missed words, extra words/spaces/etc) are made, there seems to be no LOGICAL way to compare the second textbox content with the first one.
For example:
First TB: "DataMiser is a great VB6 Coder."
Second TB (intially blank): As the user starts typing, DataMiser is highlighted, but if one types in "Data Miser" then "is" would be highlighted when he starts "Miser", and then when he starts "is", "a" would be highlighted...he'll be off at least as many words as he has extra spaces in the textbox.
Then, how does he check
"Data Miser is a real bad V6 codre" vice "DataMiser is a great VB6 coder"? See what I mean? Kinda difficult, I would think.
It would likely need to be a multi step kind of thing.
There may very well be cases to where it may be to involved to highlight every mistake but should be doable.
Off the top of my head you do the array(s) as I first mentioned you can compare the count in the array and see it there are the same number of words in each.
You can loop through start to end and compare each word then if it did not match or if multiple words in a row did not match you could loop through it again end to start.
If the user made enough mistakes that it gets thrown way out of sync using both methods then maybe the typist has issues and would receive a poor score.
Dear Sam and DM,thanks for your replies. I am making my question more clear. I need printing of words attempted in first rtfphrase box (yellow) the words which become green or red after typing. It can be done if the attempted words of rtfphrase be replicate in printing form text box and then print of printform can be taken. I added a code in txtTyping_KeyPress "frmPrint.Text1.Text = Me.txtTyping.Text" , but it just show the attempted plain text in text1 of frmprinting, but for record /printing I want that mistakes (red text) should be shown as underline in the printing. Thanks (plz rename form print as frmprint in the project)
I see what you want now.....it is definitely a matter of using functions like, split(), mid() and/or Instr().
In the RichTextBox text property, the formatting characters appear...its a 'simple' matter of parsing out the string(s) that follow the "red255" characters (red255 indicating that the text is highlighted in red, or IOWs, it was incorrect). And I say 'simple' even though it will take you some time to figure out what text you want to capture. It appears that red highlighted text strings are preceeded by" cf2\ul" and followed by "\cf0\ulnone". So, I believe you can use those functions to identify your red text, and then simply transfer that text (after parsing, of course) to your other form.
Hope that helps. If I find time today, I'll look again and see if I can narrow it a little further for you, but what I said APPEARS to be a solution.
Here funky22, try this....works for me (putting the words into a listbox, but you can easily redirect to the listbox on your other form instead):
Code:
Dim myPhase As String
Dim y As Integer
Dim sArray() As String
sArray = Split(rtfPhrase, "cf2\ul")
Dim x As Integer
For x = 0 To UBound(sArray)
y = InStr(1, sArray(x), "ulnone")
If y > 0 Then
myPhrase = Mid(sArray(x), 1, y - 6)
End If
List1.AddItem myPhrase 'write to your other form rather than add to this listbox I used
'as an example
Next x
PS--that should read "for x = 1 to Ubound(sArray)"
Also, if the FIRST word is misspelled, then you'll have to modify the code as it won't work. (I'll let YOU figure out that one.)
Sammi
Dear Sam, first of all my sincere thanks for giving your precious time on my query. I put the code in print command, but could not get result. Can you please upload the project in which you have made changes. Thanks in advance.
Man, I wish I could, but I won't be back at my work computer for six more days. I had to do quite a bit to your code (as you used hardcoded paths, and had some other things that needed changing. I don't have that project with me and really don't fell like going through that whole procedure again. If you can wait until Tuesday, I can do so.
But, what are you finding is not working (remember, I said that if you spell the first word correctly, it will give you the results you asked for (in a list box I added to your main form))?
I put a commandbutton on your main screen just to test it. And put that code above in the click event of that button. Then I ran your project (with necessary changes for my environment), started the typing test, intentionally misspelling some words along the way, and then before the timer went off, I clicked the commandbutton and it printed all of the words underlined in red (caused by misspellings) into the listbox I added.
Why don't you try the same. If it works for you, you simply need to place very similar code in your 'print' button and direct the output to the other form's listbox that you had created to display those missed words.
I put a listbox on main form, a command button and put the code in it, but getting error on myphrase = Mid(sArray(x), 1, y - 6) variable not denied. waiting for ur early reply. Thanks.
Ah, I see....I misspelled myPhrase in the DIM statement
see how I had "Dim myPhase..." instead of "Dim myPhrase..." I left out the 'r'...So,
simply add that 'r' in there and it should work (must be I didn't have Option Explicit on (as you did not in YOUR form, I believe). But now you must, so do that
I made the correction, delete Option Explicit, now getting one or two plain text in listbox, not the total attempted words (green and red in the list box) I need printing of these green/red words with formatting i.e. underline which are wrongly spelled.
I didn't know the green showed when misspelled, thought only the red.
(Do NOT delete your Option Explicit---it can only lead to issues down the road....simply make sure you declare all your variables and Constants.)
I'd have to relook what the string is of the whole top textbox after typing and making mistakes in the lower one. Then, I'd have to see where the GREEN showed, vice the Black and Red and parse out those words similarly to the way I did for the red.
When I did it, ALL the red (all the misspelled words) showed up in my textbox.
As I will not be able to check this out until next week, I'd suggest you look carefully at the text string (if the first rtf) before and after you type. That should give you clues on what appears in the string when text turns to green. Like I said, however, all the words "I" misspelled appeared in red, and my code worked fine for those.
Rabindranath Tagor was a Bengali polymath hwo reshapd his region's literature and music. Author of Gitanjali and its "profoundly sensative
Suppose this is the test conducted by the user. User typed 20 words, out of which 4 words are wrongly typed and shown as Red and underline. I need printing of this 20 words typed paragraph, with formatting i.e. underline. I think it can be possible, if the entire typed words are replicate in another rich text box (with formatting) and then its print can be taken.
If that is all you wanted to do (instead of LISTING the wrongly spelled words), simply set a new rtf box to whatever is in the current (your top one). It will bring over the formatting. But, you could also, at the same time you are changing the formatting in your top rtfbox (as you are typing in the bottom one), simply add that text to a third rtf on the other form.
don't use the .text property....simply rtfbox1 (or whatever the name of it was). .Text property doesn't seem to carry over the formatting, but the default property (whatever that is--I don't use rtfBoxes) does.
What are you talking about? Nowhere near the same. In YOUR link, the user MUST spell a word correctly before continuing....not much of a test as compared to OP's.
Sam, I tried rtb1 = rtfphrase, it copied entire text of rtfphrase including black letters, which have not been attempted by the user. Any idea to get only green and red texts in rtb1. ??? Thanks
The only way I can see to do that, is one again, use split/instr/mid function(s) to parse out those specific strings. Again, I can't look at this until Tuesday, but if you don't have a solution by then, I'll see what I can do. Should be relatively simple, but I need to once again see the rtf formatted text once again.
Maybe, if you can capture the following three things and post, I (or others) might be able to assist earlier:
1-Snapshot of the rtfbox showing what the user sees (black, red, green)
2-The STRING (which will have formatting embedded code) BEFORE any typing is done in the other rtfbox.
3-The STRING (as above in 2) AFTER typing is completed in the other rtfbox.
That way, we can compare the differences and possible see how to parse it (that is what I did originally to capture all the red (misspelled) words.
well, Funky, I am back. This is what I found, and I think you can handle it from here. I used a much simply textfile for my test. I printed out the actual value of the RTF before and after doing the typing test. What I found is very interesting. These two images show what I mean. This first image is what it looks like on the screen (notice the misspelled words are in red---YOUR code).
This second image shows the value of the RTF after the test is done (I copied it's contents to a multiline textbox). I then copied that into MS Word so I could show you the 'mark-up language' (I'll call it) that distinguishes between red and green words (I colored them in MS Word to help you see). You should be able to now parse the 'green' words easily, as well as the 'red' words based upon using a combination of Split(), Instr() and/or Mid() functions. That SHOULD solve your problem.
Here is a tiny program that takes that text and calculates the misspelled words and the correctly spelled words and puts each in its own listbox....it shows how "I" split up that text that would be in your RTFbox....hope you can implement similar in your program.