Lately, in this forum, there were many questions and problems referring to the use of ie.au3 UDF using the latest version of AutoIt v3.3.14.x. I would like to present the correct usage of the UDF. I hope that it will help many users to prevent problems. #include <ie.au3>
#include <MsgBoxConstants.au3>
; STEP 1
; YOU MUST SET ANY COM ERROR HANDLER IN ONE OF THE FOLLOWING WAY
; STEP 1: CASE 1
; you should set COM Error Handler Function for ie.au3 UDF
_IEErrorHandlerRegister(_User_ErrFunc)
; STEP 1: CASE 2
; eventually if you not want to recieve additional information
; you can use just the same function without parameter
; _IEErrorHandlerRegister()
; STEP 1: CASE 3
; or use your own global COM Error Handler
;~ Global $oCOMErrorHandler = ObjEvent("AutoIt.Error", _User_ErrFunc)
; STEP 2
; if you do not wish to get in Console Output Pane information like the following:
; --> IE.au3 T3.0-2 Error from function _IEAction(click), $_IESTATUS_InvalidDataType
; You can uncomment this following line:
; _IEErrorNotify(False)
_Example()
Func _Example()
; First lets create some IE Object
Local $oIE = _IECreate('google.com')
; you should always check for @error in any function (even you own made)
If @error Then
MsgBox($MB_ICONERROR, '_IECreate', '@error = ' & @error & @CRLF & '@extended = ' & @extended)
; Set @error when you return from function with Failure
Return SetError(1,0,0)
Endif
; here we try to get reference to LuckyStrike button
Local $oLuckyStrike = _IEGetObjByName($oIE, 'btnI')
; you should always check for @error in any function (even you own made)
If @error Then
MsgBox($MB_ICONERROR, '_IEGetObjByName', '@error = ' & @error & @CRLF & '@extended = ' & @extended)
; Set @error when you return from function with Failure
Return SetError(2,0,0)
Endif
; here we try to click LuckyStrike button with previously achieved Object which is a reference to HTML DOM OBJECT in IE Instance
_IEAction($oLuckyStrike, 'click')
; you should wait when page is loading
_IELoadWait($oIE)
; some user interaction
If MsgBox($MB_YESNO, 'Question', 'Do you want to back ?') = $IDYES Then
_IEAction($oIE, 'back')
EndIf
EndFunc ;==>_Example
; User's COM error function.
; After SetUp with ObjEvent("AutoIt.Error", ....) will be called if COM error occurs
Func _User_ErrFunc($oError)
; Do anything here.
ConsoleWrite(@ScriptFullPath & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _
@TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _
@TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _
@TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _
@TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _
@TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _
@TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _
@TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _
@TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _
@TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF)
EndFunc ;==>_User_ErrFunc
Regards, mLipok