Good morning, I'm trying to register with NetExpress 3.0
$set ooctrl( P)
........
wordapp is class "$OLE$wordXX.application"
......
invoke EntryCallback "new" using z"myHandler"
returning aHandler
invoke ExceptionManager "register" using OLEExceptionManager
aHandler
invoke wordapp "new" returning wordServer
But it does not work, abort the program by RTE 198
I know it is very old compiler, but I do it with this version.
I remember that once worked and is a demo of this compiler.
If anyone can help, I appreciate it.
Thanks in advance.
Pedro Frongillo.
I am not sure about Net Express 3.0 but I can show you the following examples which work with other Net Express versions.
Look at exception handling demo in KB article here:
The following example is from Net Express 5.1 and it does work with COM exception handling.
*> This is required for OLE applications
$set ooctrl( P)
****************************************************************
* Copyright (C) 1997-1999 Micro Focus International Ltd.
* All Rights Reserved.
****************************************************************
* The program demonstrates the use of OLE Automation to *
* send messages to objects in another application. This *
* example uses Microsoft Word. *
* *
* It also demonstrates exception handling with regard to OLE *
* objects, and the OLE support timeout method. *
* *
* The Word interface is documented in the file vbawrd8.hlp *
* shipped with Microsoft Word 97 and vbawrd9.chm shipped *
* with Microsoft Word 2000. *
* *
* REQUIREMENTS: Microsoft Word 97 or above needs to be *
* installed. *
* *
* $(#) V1.0 *
****************************************************************
program-id. worddemo.
class-control.
*> Native Object COBOL classes
entrycallback is class "entrycll" *> Callback class
exceptMgr is class "exptnmgr" *> Exception manager class
olesup is class "olesup" *> OLE support class
oleExceptMgr is class "oleexpt" *> OLE exception class
*> OLE automation classes
wordapp is class "$OLE$word.application"
.
working-storage section.
01 wordServer object reference value null.
01 theDocument object reference value null.
01 theDocuments object reference value null.
01 theSelection object reference value null.
01 theFind object reference value null.
01 theParagraph object reference value null.
01 theParagraphs object reference value null.
01 theRange object reference value null.
01 osException object reference value null.
01 lnkNullReference object reference value null.
01 found pic s9(9) comp-5.
*> Required for re-entrancy (callback entry point below)
local-storage section.
*> Parameters for exception callback
linkage section.
01 lnkErrorNumber pic x(4) comp-5.
01 lnkErrorObject object reference.
01 lnkErrorText object reference.
procedure division.
*> Set the timeout for the OLE "busy" error to 100ms
*> Using this method is recommended for Word applications
invoke olesup "setOLEBusyTimeout" using by value 100
*> Create an instance of Word
invoke wordapp "new" returning wordServer
*> Exception handling: Register a callback to be used
*> whenever an exception is raised on the OLE exception class
invoke entrycallback "new" using z"onOleException"
returning osException
invoke exceptmgr "register" using oleExceptMgr
osException
*> Make it visible
invoke wordServer "SetVisible" using by value 1
*> Get the Word documents collection object
invoke wordServer "getDocuments" returning theDocuments
*> Create a new document. The Template and NewTemplate
*> parameters for this method are optional
invoke theDocuments "add"
*> We no longer need the Documents collection
invoke theDocuments "finalize" returning theDocuments
*> Get the current selection
invoke wordServer "getSelection" returning theSelection
*> Insert some lines of text in the new document
invoke theSelection "InsertAfter" using
"This is a test line" & x"0d"
invoke theSelection "InsertAfter" using
"This is the third line" & x"0d"
*> Finished with the selection object
invoke theSelection "finalize" returning theSelection
*> Oops - we've put "third" instead of "second"
*> So, we'll replace that word. This is a bit convoluted,
*> but it's intended to give an idea of how collections work
*> Get the active document
invoke wordServer "getActiveDocument" returning theDocument
*> Get the Paragraphs collection, then the second paragraph
*> using the item method, then the range of that paragraph;
*> Once we have the range, we've finished with paragraphs!
*> This does *exactly* the same as the VB command
*> Range = Document.Paragraphs(2).Range
invoke theDocument "getParagraphs" returning theParagraphs
invoke theParagraphs "item" using by value 2
returning theParagraph
invoke theParagraph "getRange" returning theRange
invoke theParagraph "finalize" returning theParagraph
invoke theParagraphs "finalize" returning theParagraphs
*> Get the Find object and ask it to find the text "third"
*> This should change theRange object's character range
invoke theRange "getFind" returning theFind
invoke theFind "setForward" using by value 1
invoke theFind "setText" using by content z"third"
invoke theFind "execute"
invoke theFind "getFound" returning found
invoke theFind "finalize" returning theFind
if found not = 0
*> Select our new range of characters
invoke theRange "select"
*> Finally, change the word to the correct word!
invoke theRange "setText" using "second"
end-if
invoke theRange "finalize" returning theRange
*> Print the document out
invoke theDocument "PrintOut" using by value 0
*> Close it without saving it
invoke theDocument "Close" using by value 0
*> We've finished with the document object
invoke theDocument "finalize" returning theDocument
*> Tell Word to quit (it won't shut down otherwise)
invoke wordServer "quit"
*> We've now finished with the Word object
invoke wordServer "finalize" returning wordServer
exit program
stop run.
callback section.
entry "onOleException" using by reference lnkErrorObject
by reference lnkErrorNumber
by reference lnkErrorText.
display "Word97 had returned an error..."
display "The COBOL exception number was: " lnkErrorNumber
display "The exception occured on:"
invoke lnkErrorObject "display"
display " "
if lnkErrorText not = null
invoke lnkErrorText "display"
display " "
end-if
stop "Press a key to continue"
exit program returning lnkNullReference.
Good morning, I'm trying to register with NetExpress 3.0
$set ooctrl( P)
........
wordapp is class "$OLE$wordXX.application"
......
invoke EntryCallback "new" using z"myHandler"
returning aHandler
invoke ExceptionManager "register" using OLEExceptionManager
aHandler
invoke wordapp "new" returning wordServer
But it does not work, abort the program by RTE 198
I know it is very old compiler, but I do it with this version.
I remember that once worked and is a demo of this compiler.
If anyone can help, I appreciate it.
Thanks in advance.
Pedro Frongillo.
Good afternoon, Dear Mr. Chris Glazier:
I appreciate your quick response.
Obviously with version 3.0 is not possible to trap the error before the program crashes on the RTS 198.
It is possible from version 3.1 or greater through
invoke OLESup "isServerRegistered" using z"Word.Application" .....
This feeds the affirmation of my colleagues argue that "Cobol is Dead", since with older versions of C, Delphi, etc, etc, they resolved with three lines of code.
I have no choice but to call a DLL developed in another language.
Thank you very much for your time and expertise.
Pedro Frongillo.
Good morning, I'm trying to register with NetExpress 3.0
$set ooctrl( P)
........
wordapp is class "$OLE$wordXX.application"
......
invoke EntryCallback "new" using z"myHandler"
returning aHandler
invoke ExceptionManager "register" using OLEExceptionManager
aHandler
invoke wordapp "new" returning wordServer
But it does not work, abort the program by RTE 198
I know it is very old compiler, but I do it with this version.
I remember that once worked and is a demo of this compiler.
If anyone can help, I appreciate it.
Thanks in advance.
Pedro Frongillo.
Sorry, but I must disagree with your colleagues argument that "Cobol is Dead" based on the premise that you cannot register a COM exception handler developed in an unsupported 15 year old version of Net Express.
Your other choice would be of course to upgrade to a newer supported version of Net Express or to open up a support incident with Micro Focus so that we could actually analyze the problem that you are having.
Thanks.
Good morning, I'm trying to register with NetExpress 3.0
$set ooctrl( P)
........
wordapp is class "$OLE$wordXX.application"
......
invoke EntryCallback "new" using z"myHandler"
returning aHandler
invoke ExceptionManager "register" using OLEExceptionManager
aHandler
invoke wordapp "new" returning wordServer
But it does not work, abort the program by RTE 198
I know it is very old compiler, but I do it with this version.
I remember that once worked and is a demo of this compiler.
If anyone can help, I appreciate it.
Thanks in advance.
Pedro Frongillo.
Of course I agree with you, I development Cobol systems since 1969 and still do.
Thanks again and have a good day.
Pedro Frongillo.