• Welcome to Theos PowerBasic Museum 2017.

Problem using direct method

Started by Gil Ben-Zvi, November 16, 2009, 05:39:11 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Gil Ben-Zvi

Any idea why the following code crashes?

MSWord 2007 Interface defintions file ("Office12.inc") generated using PBrow.


Sub Speller(UWord As String)
 
  Local oWordApp        As Int__Application      ' Application Interface.
  Local oWordDoc        As Int__Document         ' Document Interface.
  Local oSuggestions    As SpellingSuggestions   ' Spelling Suggestions collection object.
  Local NumWords        As Long

  ' Open a new instance of MSWORD
  oWordApp = NewCom $PROGID_Word_Application
  If IsTrue IsObject(oWordApp) Then
     ' Must have at least one document.
     If oWordApp.Documents.Count = 0 Then
        oWordDoc = oWordApp.Documents.Add
     End If
     oSuggestions = oWordApp.GetSpellingSuggestions(UWord)
     If IsObject(oSuggestions) Then
        ' CRASH ON NEXT STATEMENT.
        NumWords = oSuggestions.Count
        If oSuggestions.SpellingErrorType <> %WdSpellingErrorType_wdSpellingCorrect Then
           
        End If
       
     End If
  End If

End Sub


Gil.

Paul Squires

I may be 100% wrong, but I thought that I remembered Jose mentioning that all of the Office applications (Word, Excel, etc...) operate using a Dispatch interface instead of a direct interface.
Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

Paul Squires

Actually, Jose kind of alludes to this in his comments about Excel in another post from today: http://www.jose.it-berater.org/smfforum/index.php?topic=3364.0
Paul Squires
FireFly Visual Designer SQLitening Database System JellyFish Pro Editor
http://www.planetsquires.com

José Roca

 
And not only that. If you want to be safe, use late binding because M$ has broken all his COM rules with these applications and, if you use early binding, an application compiled using an include file for one version may crash when used with a different version.

The object model of the Office applications has been designed to work mainly with VBA.