-
May 14th, 2015, 07:38 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Dictionary Access
I have written a small VB 6 program using the Microsoft Word 11.0 object library. The program works fine when I declare "dim mwd as New Word.Application" and declare "Dim mwdsp as Word.SpellingSuggestions".
But the dictionary that comes with Office 11.0 is rather old. I don't think I can attach a newer dictionary to MS Word 2003. Without moving on .NET, how can I access a newer dictionary, or a more comprehensive American English dictionary in VB6 without changing my code?
Thanks
-
May 14th, 2015, 08:51 AM
#2
Re: Dictionary Access
I have not idea WHAT dictionary my Office 2013 uses..., but with this code in a module, I spell check my apps with it:
(accessed like:
Code:
Clipboard.Clear
Clipboard.SetText Text3.Text
Text3.Text = SpellChk()
)
Code:
Option Explicit
Declare Function CoAllowSetForegroundWindow Lib "ole32.dll" (ByVal pUnk As Object, ByVal lpvReserved As Long) As Long
Public Function SpellChk() As String
Dim WordApp As Object
Dim objDoc As Object 'Word.Document
Dim lOrigTop As Long
Dim lErr As Long
On Error GoTo SpellChkErr
' Create a Word document object
Set WordApp = CreateObject("Word.Application")
CoAllowSetForegroundWindow WordApp, 0
Set objDoc = WordApp.Documents.Add
' Position Word off screen to avoid having document visible
lOrigTop = WordApp.Top
WordApp.WindowState = 0
WordApp.Top = -3000
WordApp.Visible = True
WordApp.Activate
' Assign the text to the document and check spelling
With objDoc
.Content.Paste
.Activate
.CheckSpelling
' After the user has made changes, use the clipboard to
' transfer the contents back to the text box
.Content.Copy
SpellChk = Clipboard.GetText(vbCFText)
' Close the document and exit Word
.Saved = True
.Close
End With
Set objDoc = Nothing
WordApp.Visible = False
WordApp.Top = lOrigTop
WordApp.Quit
Set WordApp = Nothing
Exit Function
SpellChkErr:
lErr = Err
SpellChk = Clipboard.GetText(vbCFText)
Screen.MousePointer = vbNormal
Select Case lErr
Case 91, 429
MsgBox "MS Word cannot be found!", vbExclamation
Case Else
MsgBox "Error: " & Err & " - " & Error$(Err), vbExclamation, App.ProductName
End Select
End Function
-
May 14th, 2015, 09:50 AM
#3
Re: Dictionary Access
And for the OP, the difference is that you are loading a specific version of Word (early binding) whereas Sam is loading whatever version the user may have (late binding). In either case, Word is assumed to be present. There are differences with how you have to create the objects using Early vs. Late binding
-
May 14th, 2015, 12:49 PM
#4
Thread Starter
Fanatic Member
Re: Dictionary Access
Why would my OS have a different Dictionary. I thought MS Office Pro supplies the dictionary?
Thanks
-
May 14th, 2015, 03:12 PM
#5
Re: Dictionary Access
Don't know if dictionary is different or not. Different versions of MS, possibly different versions of the dictionary (more current for newer Office versions). Does MS have a single dictionary it shares among all versions of office? Don't know.
-
May 14th, 2015, 04:00 PM
#6
Thread Starter
Fanatic Member
Re: Dictionary Access
Used supplied code from SamOscarBrown and got the same answer as with my code. The same dictionary was referenced by bot code.
-
May 14th, 2015, 04:05 PM
#7
Re: Dictionary Access
That is to be expected, as SamOscarBrown's code uses whatever version of Word is installed, so will be using the same version as your code does.
-
May 14th, 2015, 04:07 PM
#8
Re: Dictionary Access
Well to try to answer this question, if I'm understanding you correctly
Originally Posted by AccessShell
But the dictionary that comes with Office 11.0 is rather old. I don't think I can attach a newer dictionary to MS Word 2003. Without moving on .NET, how can I access a newer dictionary, or a more comprehensive American English dictionary in VB6 without changing my code?
You can only access whatever MS Office dictionary is on the user's system with the code you have. And I would think that if the user had a version less than Office 11, you would get an error; whereas Sam's code doesn't care which Office version exists as long as the Word application has the methods/properties he used in his sample code. The same office dictionary, I'd imagine, is used with all installed office products on that machine.
To use another dictionary (online or on the system), you'll need to change your code to include calling whatever methods/properties that that specific dictionary exposes.
-
May 14th, 2015, 04:18 PM
#9
Thread Starter
Fanatic Member
Re: Dictionary Access
I fully agree with you LaVolpe. I think, then, If I am able to get another dictionary on my computer, or via an online inquiry, I might be able to access that dictionary with some modified code. I don't think there are any VB6 references, components or objects that easily does this.
-
May 14th, 2015, 04:42 PM
#10
Re: Dictionary Access
Well couple problems with on-line dictionaries:
1) user's network availability & will the target site be available
2) will the online site allow you to manipulate it remotely for this purpose?
3) can it spell-check more than 1 word at a time?
4) will it give you suggested corrections?
Problems with other dictionaries (not Office)
1) you'll need to transfer those with your program's setup files
2) who updates these?
3) when updated, now you need to redistribute the dictionary
Example: There is a project on planetsourcecode. How often is that updated, if at all? See 2nd post in this thread
And of course, what if no dictionary is available at all? If you're not distributing one, then you simply can't do spell checks, can you?
Last edited by LaVolpe; May 15th, 2015 at 11:44 AM.
-
May 15th, 2015, 09:46 AM
#11
Thread Starter
Fanatic Member
Re: Dictionary Access
I looked at the code you suggested. Downloaded it and ran it. Sometimes it worked; sometimes it didn't. Besides, the code is way to advanced for me. I lost it in VB6 when classes were developed. I now only write without classes.
Thanks for your help. I think I will consider this thread closed.
-
Jan 10th, 2023, 12:09 PM
#12
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
I did some some digging into this. When I ran the program on WIN 10, I got this error
"Err.Source = C:\WINDOWS\Help\VBENLR98.CHM"
"Err.Description = Automation error Library not registered."
"Err.HelpContext = 1000440"
I don't know what a "CHM" file is. This file is not present anywhere on my WIN 10 computer. However, I looked at my WIN 7, VMXP, computer and did NOT find this file either. Yet, the program works on VMXP.
I believe the program was originally written in January of 2003. I don't know what version of VB existed then.
Could that have anything to do with the problem?
I looked on the VMXP computer and could not find the CHM file. I was going to copy it onto the WIN 10 computer.
-
Jan 10th, 2023, 12:23 PM
#13
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
This is the code
Code:
Private Sub cmdCheck_Click()Dim wd As New Word.Application
Dim wdsp As Word.SpellingSuggestions
Dim i As Integer
Dim strBuffer As String
Dim varBuffer As Variant
Dim synList As Variant
Dim antList As Variant
Dim synFound As Boolean
On Error GoTo cmdCheckErr
lblSugs.Caption = NUM_OF_SUGS & CStr(0)
lblSyns.Caption = NUM_OF_SYNS & CStr(0)
lblAnts.Caption = NUM_OF_ANTS & CStr(0)
lblMsg.Caption = ""
lstSuggestions.Clear
lstSynonyms.Clear
lstAntonyms.Clear
strBuffer = txtMain.Text
cmdCheck.Enabled = False
cmdQuit.Enabled = False
frmMain.MousePointer = vbHourglass
wd.Documents.Add '***DIES HERE***********************************
If Not wd.CheckSpelling(strBuffer) Then
txtMain.ForeColor = vbRed
lblMsg.Caption = "Spelling Incorrect!"
lblMsg.ForeColor = vbRed
Set wdsp = wd.GetSpellingSuggestions(strBuffer)
lblSugs.Caption = NUM_OF_SUGS & CStr(wdsp.Count)
For i = 1 To wdsp.Count
lstSuggestions.AddItem wdsp(i).Name
Next i
Else
varBuffer = CVar(strBuffer)
lblMsg.Caption = "Spelling OK"
lblMsg.ForeColor = vbBlue
varBuffer = CVar(strBuffer)
'Get the Synonyms
synFound = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).Found
If synFound = True Then
synList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
For i = 1 To UBound(synList)
lstSynonyms.AddItem synList(i)
Next i
lblSyns.Caption = NUM_OF_SYNS & CStr(UBound(synList))
End If
'Get the Antonyms
'antList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).AntonymList
antList = SynonymInfo(varBuffer, wdEnglishUS).AntonymList
For i = 1 To UBound(antList)
lstAntonyms.AddItem antList(i)
Next i
lblAnts.Caption = NUM_OF_ANTS & CStr(UBound(antList))
End If
wd.Documents.Close
wd.Quit
Set wd = Nothing
txtMain.ForeColor = vbBlack
frmMain.MousePointer = vbDefault
cmdCheck.Enabled = True
cmdQuit.Enabled = True
Exit Sub
cmdCheckErr:
MsgBox Err.Description & ", " & Err.Number
Debug.Print "Err.Description = " & Err.Description & _
"Err.HelpContext = " & Err.HelpContext & _
"Err.HelpFile = " & Err.HelpFile
wd.Quit
End Sub
-
Jan 10th, 2023, 03:03 PM
#14
Re: [RESOLVED] Dictionary Access
VBENLR98.chm is a compiled HTML file, a help file for the Microsoft scripting runtime.
https://github.com/yereverluvinunclebert
Skillset: VMS,DOS,Windows Sysadmin from 1985, fault-tolerance, VaxCluster, Alpha,Sparc. DCL,QB,VBDOS- VB6,.NET, PHP,NODE.JS, Graphic Design, Project Manager, CMS, Quad Electronics. classic cars & m'bikes. Artist in water & oils. Historian.
By the power invested in me, all the threads I start are battle free zones - no arguing about the benefits of VB6 over .NET here please. Happiness must reign.
-
Jan 10th, 2023, 03:17 PM
#15
Re: [RESOLVED] Dictionary Access
I added spellchecking in my "build-in" game-editor so the writer has a bit of help when writing the dialogs/text.
a few things I needed to do was to create a "error-handler", this because sometimes word would close, if so, the program would re-initialize.
so, 1 year passed and another person wanted to help with a side-story, but he got a crash. and investigating it showed word was the culprit.
he told me has word, but not the spell-checking.
after that I removed it all and created my own spell-checking function. and Im quite happy with that. now theres no problem whoever use it,
since its not dependent of word and what OS and version or addon the person has.
-
Jan 10th, 2023, 03:32 PM
#16
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
That doesn't explain why, in my case, the version of Word is the same (2003).
Nor why the CHM file does not appear in either OS. Yes, I still have my WIN 7 with the VMXP. The only difference, I am aware of, is the WIN 7 (witt the VMXP) is NOT connected to the internet.
Last edited by AccessShell; Jan 10th, 2023 at 03:35 PM.
-
Jan 10th, 2023, 03:45 PM
#17
Re: [RESOLVED] Dictionary Access
the problem is NOT the CHM but:
Automation error Library not registered
it means word is not working properly.
-
Jan 10th, 2023, 03:52 PM
#18
Re: [RESOLVED] Dictionary Access
Originally Posted by AccessShell
That doesn't explain why, in my case, the version of Word is the same (2003).
Why would it be different? If you've got Word 2003 installed, that's what going to be used. If you were to upgrade it to a newer version and use Sam's code... then you should see it using a different version.
-tg
-
Jan 10th, 2023, 04:12 PM
#19
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Does this mean that all I need do is reinstall MS Office 2003 Pro? I don't have MS Office 365 installed. Is that a deal breaker? Is MS trying to tell me use 365?
-
Jan 10th, 2023, 04:40 PM
#20
Re: [RESOLVED] Dictionary Access
each word is different and can have a different structure.
also, it can be its not initialized correctly, or its not registered correctly to the register so VB can fetch it.
or the register has a wrong ID, so there no match.
but the problem is word.
wd.Documents.Add
Documents.Add < is not a valid command.
could be u need to do
wd.-something-.Documents.Add or something else.
thats the problem here. u need to know the right command.
when I used word, we had different versions. but it worked because all word versions did have the same command.
I have not used Documents.Add
-
Jan 10th, 2023, 05:07 PM
#21
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
-
Jan 10th, 2023, 05:59 PM
#22
Re: [RESOLVED] Dictionary Access
could be that as well.
but I know that not all commands are the same.
try to remove Documents.Add and see what happens.
I only used word by word. so I never did grammar.
worked for me. but word need to have spell-dictionary installed.
or create your own spell-check, is not that hard to do.
-
Jan 10th, 2023, 06:46 PM
#23
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
I don't know why I didn't try this before, I ran the original code on the Win7 computer. It runs correctly. It lists the word and it's synonyms and antonyms correctly if it is a word. Otherwise, It gives suggestions for correct words.
-
Jan 11th, 2023, 02:31 PM
#24
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Even though the program crashes, I successfully compiled it. Of course, it crashed on my computer. (Win Ver 22H2, but last week it was 21H2 and it still crashed).
I copied the exe onto my friends Win10 laptop (21H2) with Office 2003 Pro. That computer does not have VB6 installed. The program worked correctly.
I am now even more confused.
-
Jan 11th, 2023, 02:45 PM
#25
Re: [RESOLVED] Dictionary Access
I told u, its Documents.Add that is not working.
the word version in your computer don't have that command so it crash.
-
Jan 11th, 2023, 03:46 PM
#26
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
I just said that my friend's computer has the same version of Word - Office Pro 2003
-
Jan 11th, 2023, 04:32 PM
#27
Re: [RESOLVED] Dictionary Access
something is different.
did u try to remove Documents.Add and only use the CheckSpelling function and see if it works.
if not, it means theres something wrong with the registry.
-
Jan 11th, 2023, 04:37 PM
#28
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Yes. No change. Do you think I should re-install Office?
-
Jan 11th, 2023, 04:41 PM
#29
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Oh, I wonder. I also have LibreOffice installed on my computer. Maybe there is an interaction?????
-
Jan 12th, 2023, 08:19 AM
#30
Re: [RESOLVED] Dictionary Access
create a new project and add this
Code:
Dim wd As Object
Dim enable As Boolean
Function CheckWord(ByVal Word$) As Boolean
If enable Then
On Error GoTo isError
CheckWord = wd.CheckSpelling(Word$)
End If
Exit Function
isError:
InitializeWord
End Function
Sub InitializeWord()
On Error Resume Next
Set wd = Nothing
Set wd = CreateObject("Word.Application")
If Err.Number = 0 Then
enable = True
wd.Options.IgnoreMixedDigits = False
wd.Options.IgnoreUppercase = False
End If
End Sub
Sub DestroyWord()
If enable Then
On Error Resume Next
wd.quit
Set wd = Nothing
enable = False
End If
End Sub
Private Sub Form_Load()
InitializeWord
Debug.Print CheckWord("testing")
Debug.Print CheckWord("wordnotfound")
DestroyWord
End Sub
and see if it works or not.
this is what I used in my program before I changed to my own spellcheck function.
-
Jan 12th, 2023, 09:01 AM
#31
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Baka, your code works. I will rewrite my program.
I have searched the internet for "Automation error Library not registered". I discovered that the code
is not really the problem. All article I found suggest that I may have remnants of another version of "Office" on my computer. The only real solution is to go into the registry and delete the others. I don't remember any other office on this computer. I do remember being nagged my MS for Office 365. I finally removed the nag. I don't remember how.
I am not eager to go into the registry.
-
Jan 12th, 2023, 09:42 AM
#32
Re: [RESOLVED] Dictionary Access
in my code add:
Code:
Private Sub Form_Load()
InitializeWord
wd.Documents.Add
Debug.Print CheckWord("testing")
Debug.Print CheckWord("wordnotfound")
DestroyWord
End Sub
and see what happens. will wd.Documents.Add cause the same "Automation error Library not registered"?
because u are using
Dim wd As New Word.Application
and that could be the problem.
its the same with "flash" it works only if I make it dynamically using: Set Flash = Controls.Add("ShockwaveFlash.ShockwaveFlash", "Flash")
if I add it to the components, it will cause issues in IDE. so maybe u need to create word from CreateObject
if u check SamOscarBrown example, he also use CreateObject
Last edited by baka; Jan 12th, 2023 at 09:49 AM.
-
Jan 12th, 2023, 11:01 AM
#33
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Baka, in your new code, it does NOT give any errors. Thanks
I will try to modify my original code!
-
Jan 12th, 2023, 02:24 PM
#34
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
Baka, I have integrated your code into my program. When the word is INcorrect, the program works correctly. It even gives a list of suggestions.
If you refer to post #13 above, and look at what happens when the word is correct. The program correctly identifies the word as correct. However, when it tries to get a list of synonyms and antonyms, it crashes again with the same error as before
"Automation error Library not registered".
-
Jan 12th, 2023, 02:35 PM
#35
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
This is the new code
Code:
If Not wd.CheckSpelling(strBuffer) Then txtMain.ForeColor = vbRed
lblMsg.Caption = "Spelling Incorrect!"
lblMsg.ForeColor = vbRed
Set wdsp = wd.GetSpellingSuggestions(strBuffer)
lblSugs.Caption = NUM_OF_SUGS & CStr(wdsp.Count)
For i = 1 To wdsp.Count
lstSuggestions.AddItem wdsp(i).Name
Next i
'**********************************************************************
'NOTE: Incorrect spelling works great ==> gives a list of suggestions
'**********************************************************************
Else
lblMsg.Caption = "Spelling OK"
lblMsg.ForeColor = vbBlue
varBuffer = CVar(strBuffer)
'Get the Synonyms
Set wdsp = wd.GetSpellingSuggestions(strBuffer)
synFound = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).Found
'NOTE: Now it dies on the previous line
If synFound = True Then
synList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).SynonymList(Meaning:=1)
For i = 1 To UBound(synList)
lstSynonyms.AddItem synList(i)
Next i
lblSyns.Caption = NUM_OF_SYNS & CStr(UBound(synList))
End If
'Get the Antonyms
'antList = SynonymInfo(Word:=varBuffer, LanguageID:=wdEnglishUS).AntonymList
antList = SynonymInfo(varBuffer, wdEnglishUS).AntonymList
For i = 1 To UBound(antList)
lstAntonyms.AddItem antList(i)
Next i
lblAnts.Caption = NUM_OF_ANTS & CStr(UBound(antList))
End If
txtMain.ForeColor = vbBlack
frmMain.MousePointer = vbDefault
cmdCheck.Enabled = True
cmdQuit.Enabled = True
-
Jan 12th, 2023, 03:37 PM
#36
Re: [RESOLVED] Dictionary Access
Not sure what is going on....but here is what I am now using for Spell checking...I have MS Word 2007 (has always been my favorite even though I used 2013 for a while, and will NEVER use 365!). I have no issues with it finding that words are correct when they are not. (or vice-versa)..give this a try and see...
Sam
SPELLCHECK_Example.zip
Sam I am (as well as Confused at times).
-
Jan 12th, 2023, 05:00 PM
#37
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
SamOscarBrown, I cannot open your code in VB6. I keep getting "Path not found" C:\My VB6
-
Jan 12th, 2023, 10:02 PM
#38
Re: [RESOLVED] Dictionary Access
? Not sure ? I have no hardcoded paths
Sam I am (as well as Confused at times).
-
Jan 13th, 2023, 10:14 AM
#39
Thread Starter
Fanatic Member
Re: [RESOLVED] Dictionary Access
SamOscarBrown Is this code you sent me
Code:
Private Sub Form_Load()strSearch = "Select * from myTitle"
Adodc1.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source= " & App.Path & "\churchcalendars.accdb;Persist Security Info=False;"
'adodc1.Recordset.DataSource
Adodc1.RecordSource = strSearch
'MsgBox Adodc1.Recordset.RecordCount
Adodc1.Refresh
End Sub
-
Jan 13th, 2023, 11:00 AM
#40
Re: [RESOLVED] Dictionary Access
No...at least not in this thread...
Here it is again (without a Form1.Log file).
Sammi
SPELLCHECK_Example_13Jan23.zip
Sam I am (as well as Confused at times).
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|