Author | Message | Time |
---|---|---|
Dyndrilliac | Ok, For a few months now I have been using a home-made spellcheck function to quickly check outgoing messages on my bot for common errors in spelling that I make, because either I'm typing too fast or lazy. It looks like this: [code]Public Function SpellCheck(strMessage As String) As String If InStr(strMessage, "liek") <> 0 Then strMessage = Replace(strMessage, "liek", "like") If InStr(strMessage, "soem") <> 0 Then strMessage = Replace(strMessage, "soem", "some") If InStr(strMessage, "alot") <> 0 Then strMessage = Replace(strMessage, "alot", "a lot") If InStr(strMessage, "amke") <> 0 Then strMessage = Replace(strMessage, "amke", "make") If InStr(strMessage, "amde") <> 0 Then strMessage = Replace(strMessage, "amde", "made") If InStr(strMessage, ";t") <> 0 Then strMessage = Replace(strMessage, ";t", "'t") If InStr(strMessage, ";s") <> 0 Then strMessage = Replace(strMessage, ";s", "'s") If InStr(strMessage, "bakc") <> 0 Then strMessage = Replace(strMessage, "bakc", "back") If InStr(strMessage, "ahnd") <> 0 Then strMessage = Replace(strMessage, "ahnd", "hand") If InStr(strMessage, " u ") <> 0 Then strMessage = Replace(strMessage, " u ", " you ") If InStr(strMessage, " ur ") <> 0 Then strMessage = Replace(strMessage, " ur ", " your ") SpellCheck = strMessage End Function[/code] I want to take this far beyond my original quick fix intentions and make it so it can check for thousands of errors quickly, and without adding tons of size to the program, as memory efficient as possible in VB6. If anyone could provide some tips, suggestions, resources, or any other general assistance it would be much appreciated. | September 20, 2004, 4:50 PM |
UserLoser. | Small optimization: You don't have to verify if the string you're checking is in the string you're replacing or not. Ex: Replace("test", "1", vbNullString) is going to check the string anyways to see if "1" exists, then it'll replace it, if it does. So there really isn't a point of doing InStr() first. If "1" doesn't exist, then the string will remain as "test". Also, "ur" could be debatable, whether the user is saying "ur dog" (your dog), or "ur cool" (you're cool). That would be a tough one to decide on what to replace "ur" with, and would probably require work to see the words before and/or after it | September 20, 2004, 6:49 PM |
Dyndrilliac | So, this would be fine? [code]Public Function SpellCheck(strMessage As String) As String Replace strMessage, "liek", "like" Replace strMessage, "soem", "some" Replace strMessage, "alot", "a lot" Replace strMessage, "amke", "make" Replace strMessage, "amde", "made" Replace strMessage, ";t", "'t" Replace strMessage, ";s", "'s" Replace strMessage, "bakc", "back" Replace strMessage, "ahnd", "hand" Replace strMessage, " u ", " you " Replace strMessage, " ur ", " your " SpellCheck = strMessage End Function[/code] I still need some advice on how to go about creating in a buil-in spellcheck function. I was kind of hoping to try and make it as extensive as Microsoft Word's SpellChecking thingy but without adding tons of size and resource usage by the program in VB. | September 20, 2004, 8:35 PM |
K | [quote author=Dyndrilliac link=board=31;threadid=8762;start=0#msg81109 date=1095712509] So, this would be fine? [code]Public Function SpellCheck(strMessage As String) As String Replace strMessage, "liek", "like" Replace strMessage, "soem", "some" Replace strMessage, "alot", "a lot" Replace strMessage, "amke", "make" Replace strMessage, "amde", "made" Replace strMessage, ";t", "'t" Replace strMessage, ";s", "'s" Replace strMessage, "bakc", "back" Replace strMessage, "ahnd", "hand" Replace strMessage, " u ", " you " Replace strMessage, " ur ", " your " SpellCheck = strMessage End Function[/code] [/quote] close, but you're replacing a value, discarding the result, and then replacing another value, etc. You need to save the result of the replace function. [code]Public Function SpellCheck(strMessage As String) As String strMessage = Replace(strMessage, "liek", "like") strMessage = Replace(strMessage, "soem", "some") strMessage = Replace(strMessage, "alot", "a lot") strMessage = Replace(strMessage, "amke", "make") strMessage = Replace(strMessage, "amde", "made") strMessage = Replace(strMessage, ";t", "'t") strMessage = Replace(strMessage, ";s", "'s") strMessage = Replace(strMessage, "bakc", "back") strMessage = Replace(strMessage, "ahnd", "hand") strMessage = Replace(strMessage, " u ", " you ") strMessage = Replace(strMessage, " ur ", " your ") SpellCheck = strMessage End Function[/code] | September 20, 2004, 8:59 PM |
Tuberload | One idea would be to have an English dictionary saved somewhere and compare words to it. If a word is not found, assume it is spelled wrong. Then compare the misspelled word to other similar words and depending on their likeness provide it as an option. This is the first idea that comes to mind, and I do not know how good of one it is. | September 20, 2004, 9:18 PM |
Dyndrilliac | I looked it up on MSDN and found out I could use MS Word's Spellchecker using OLE. [code]Public Function SpellCheck(strText As String) As String On Error Resume Next Dim oWDBasic As Object Dim sTmpString As String If strText = vbNullString Then Exit Function End If Screen.MousePointer = vbHourglass Set oWDBasic = CreateObject("Word.Basic") With oWDBasic .FileNew .Insert strText .ToolsSpelling oWDBasic.EditSelectAll .SetDocumentVar "MyVar", oWDBasic.Selection End With sTmpString = oWDBasic.GetDocumentVar("MyVar") sTmpString = Left(sTmpString, Len(sTmpString) - 1) If sTmpString = vbNullString Then SpellCheck = strText Else SpellCheck = sTmpString End If oWDBasic.FileCloseAll 2 oWDBasic.AppClose Set oWDBasic = Nothing Screen.MousePointer = vbNormal End Function [/code] | September 20, 2004, 11:49 PM |
K | [quote author=Dyndrilliac link=board=31;threadid=8762;start=0#msg81187 date=1095724191] I looked it up on MSDN and found out I could use MS Word's Spellchecker using OLE. (edit: snipped code) [/quote] It would probably be a good idea if you're going to be using this function repeatedly to just create the word object once instead of creating/deleting it over and over again. | September 21, 2004, 12:18 AM |
St0rm.iD | You should store the changes in a dictionary. Then think about using Google's spellcheck. | September 21, 2004, 1:40 AM |
Myndfyr | Also, be careful with replacing "ur" with "your." Sometimes people use "ur" for "you're." | September 21, 2004, 2:19 PM |
Soul Taker | [quote author=MyndFyre link=board=31;threadid=8762;start=0#msg81261 date=1095776369] Also, be careful with replacing "ur" with "your." Sometimes people use "ur" for "you're." [/quote] Read the thread =P | September 21, 2004, 3:04 PM |
hismajesty | I once saw a way to do this by interacting with Word's dictionary database. One downfall would be the necessity of the user having to have Word installed, but if that sounds like something you'd like I'm sure a simple google search would bring something like that up. | September 21, 2004, 8:17 PM |
Dyndrilliac | [quote author=hismajesty[yL] link=board=31;threadid=8762;start=0#msg81279 date=1095797845] I once saw a way to do this by interacting with Word's dictionary database. One downfall would be the necessity of the user having to have Word installed, but if that sounds like something you'd like I'm sure a simple google search would bring something like that up. [/quote] Well the fact that I'm using VB requires the user to be on Windows, therefore there is a large chance Word is also installed. | September 21, 2004, 9:24 PM |
Twix | [quote author=Dyndrilliac link=board=31;threadid=8762;start=0#msg81291 date=1095801892] [quote author=hismajesty[yL] link=board=31;threadid=8762;start=0#msg81279 date=1095797845] I once saw a way to do this by interacting with Word's dictionary database. One downfall would be the necessity of the user having to have Word installed, but if that sounds like something you'd like I'm sure a simple google search would bring something like that up. [/quote] Well the fact that I'm using VB requires the user to be on Windows, therefore there is a large chance Word is also installed. [/quote] None of the new dells come with Word | September 21, 2004, 10:49 PM |
hismajesty | The Sony Vaio comes with office, but it doesn't come with the registration key (at least, I can't find it.) :P | September 22, 2004, 12:20 AM |
SNiFFeR | [quote author=hismajesty[yL] link=board=31;threadid=8762;start=0#msg81314 date=1095812450] The Sony Vaio comes with office, but it doesn't come with the registration key (at least, I can't find it.) :P [/quote] I'm sure if you looked somewhere where you aren't suppose to you could find it ;). | September 22, 2004, 1:59 AM |