Article ID: 186298
Article Last Modified on 7/1/2004
*-- Code begins here.
ON ERROR DO getresult IN hresult WITH ;
ERROR(), MESSAGE()
*-- Create an instance of Microsoft Word.
oWord = CREATEOBJECT("Word.Application")
*-- Call an invalid function to test our error handling.
oWord.RaiseError
PROCEDURE getresult
PARAMETER liError, lsMessage
IF liError <> 1426 && Not an OLE error code
*-- Since this error handler now handles all errors, it
*-- would be best to include some more robust error
*-- handling here to handle errors other than #1426.
RETURN
ENDIF
*-- Take the message string and parse the hexadecimal HRESULT.
*-- The VAL() function will do the conversion to a base 10 integer.
liHresult = VAL(SUBSTR(lsMessage, AT("0x", lsMessage), 10))
*-- Display the result in decimal and hexadecimal format.
*-- This section would be used to process the HRESULT as needed,
*-- either by parsing the returned code or otherwise overriding the
*-- default Visual FoxPro behavior.
MESSAGEBOX("OLE function returned HRESULT: " +;
CHR(10) + CHR(13) + ;
STR(liHresult) + " (decimal) " +;
CHR(10) + CHR(13) + ;
TRANSFORM(liHresult, "@0") + " (hexadecimal)", 0, "OLE Error")
RETURN
*-- Code ends here.
Additional query words: kbDSupport kbDSE beta99 FxinteropOcx FxinteropOle FxprgGeneral vfoxwin
Keywords: kbhowto KB186298