Jump to content

how to run 2 seperate err functions with a script


Recommended Posts

How do I manage 2 seperate ErrorMsg handlers and in the same script? do I just use one and call from IE and SQL? Or I have to reg and unreg after each use?

SQL Function

_SQL_RegisterErrorHandler()
Global $oADODB = _SQL_Startup()
If $oADODB = $SQL_ERROR then LOGDATA($LEVEL, "ETSSO MANAGER DEBUG",_SQL_GetErrMsg()&@CRLF)
If _SQL_Connect($oADODB,$SQLSvr,"",$sqladm,$sqlpwd) = $SQL_ERROR then
  HideLogonprogress()
  MsgBox(4096,"Logon Failure","Either the instance name or the credentials are incorrect.")
  LOGDATA($LEVEL, "ETSSO MANAGER DEBUG","authentication Failure, or incorrectly defined SQL Server.")
  GUISetState(@SW_SHOW,$loggui)
  Return
Else
  Local $saveinfochk = GUICtrlRead($SaveInfo)
  Global $XylocSetting= GUICtrlRead($XylocInfo)
  If $saveinfochk=1 Then
   $serverinstance=GUICtrlRead($SQLSvrdata)
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Name",$serverinstance)
   $serveradmin=GUICtrlRead($SQLadmdata)
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Admin",$serveradmin)
   $serveradminpwd=GUICtrlRead($sqlpwddata)
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Pwd",_Base64Encode($serveradminpwd))
   LOGDATA($LEVEL, "ETSSO MANAGER DEBUG","Saving Credential Data in ../Data/Settings.ini.")
  Else
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Name","")
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Admin","")
   IniWrite(@ScriptDir&"\Data\Settings.ini","Server Settings","Pwd","")
   LOGDATA($LEVEL, "ETSSO MANAGER DEBUG", "Clearing ini settings in ../Data/Settings.ini." & $LEVEL)
  EndIf
  _SQL_UnRegisterErrorHandler()
  _SQL_Close()
EndIf

IE Functions

Func StartApp()
_SQL_UnRegisterErrorHandler()
_IEErrorHandlerRegister("_ErrFunc")
Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
;ConsoleWrite(GUICtrlRead($AppType1)&@CRLF)
If GUICtrlRead($AppType) = "Internet Explorer" then
  Global $oIEEvents = ObjEvent($oIE, "_IEEvent_", "DWebBrowserEvents2")
  Global $oInputs = _IETagNameGetCollection($oIE, "input")
  For $oInput In $oInputs
   ;ConsoleWrite($oInput.name&@CRLF)
    GUICtrlSetData($logontitle,_IEPropertyGet($oIE,"title"))
    GUICtrlSetData($LAppPath,_IEPropertyGet($oIE,"locationurl"))
    GUICtrlSetData($logonctrl, $oInput.name,"") ; add other item
    GUICtrlSetData($pwdctrl, $oInput.name,"") ; add other item
    GUICtrlSetData($submitctrl, $oInput.name,"") ; add other item
   Next
EndIf
EndFunc

Func ShowLogonCtrl()
_SQL_UnRegisterErrorHandler()
_IEErrorHandlerRegister("_ErrFunc")
$o_form = _IEFormGetCollection($oIE,0)
$n_Forms = @extended
;ConsoleWrite("Forms Found:"&$n_Forms&@CRLF)
$o_Elements = _IEFormElementGetCollection($o_form,0)
$n_Elements = @extended
;ConsoleWrite("Elements Found:"&$n_Elements&@CRLF)
Local $oInputs = _IETagNameGetCollection($oIE, "input")
For $oInput In $oInputs
If $oInput.name = GUICtrlRead($logonctrl,1) Then
  Global $iScreenX = _IEPropertyGet($oInput, "screenx")
  Global $iScreenY = _IEPropertyGet($oInput, "screeny")
  Local $iBrowserX = _IEPropertyGet($oInput, "browserx")
  Local $iBrowserY = _IEPropertyGet($oInput, "browserY")
  Global $iWidth = _IEPropertyGet($oInput, "width")
  Global $iHeight = _IEPropertyGet($oInput, "height")
  ConsoleWrite("X:"&$iScreenX&@CRLF&"Y:"&$iScreenY&@CRLF&"W:"&$iWidth&@CRLF&"H:"&$iHeight)
  ToolTip("Logon Control",$iScreenX,$iScreenY,"","")
  sleep(3000)
  ToolTip("")
  EndIf
Next
WinActivate(GUICtrlRead($logontitle,1))
Return
EndFunc
Link to comment
Share on other sites

Reading the help it states the following:

_IEErrorHandlerRegister("_func")

AutoIt has the ability to trap COM errors and pass them through a custom error handler using the ObjEvent function. There is a problem with this for UDF writers however because only a single COM error handler can be in use at a time. For the UDF to use a COM error handler it must first deregister the user error handler, install its own and then put the user handler back in place. Unfortunately, by default, the UDF has no way to access the handle of the user error handler.

does this mean I have to _IEErrorHandlerRegister() after I create a $IE object and _IEErrorHandlerRegister() when

I done so I can register a _SQL_RegisterErrorHandler() and then _SQL_UnRegisterErrorHandler() when I done with the SQL function?

Link to comment
Share on other sites

run a code against www.gmail.com to get controls I get and error:

--> COM Error Encountered in ETSSO_MAIN.au3

----> $IEComErrorScriptline = 348

----> $IEComErrorNumberHex = 00000002

----> $IEComErrorNumber = 2

----> $IEComErrorWinDescription = Can't install a new Errorhandler when one is still active.

----> $IEComErrorDescription =

----> $IEComErrorSource =

----> $IEComErrorHelpFile =

----> $IEComErrorHelpContext = 0

----> $IEComErrorLastDllError = 0

C:\Program Files (x86)\AutoIt3\Include\IE.au3 (2270) : ==> Object referenced outside a "With" statement.:

Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName).length, $oTemp.GetElementsByTagName($s_TagName))

Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName)^ ERROR

My code - works great with mail.yahoo.com and www.hotmail.com

Func WizGetControls()
_IEErrorHandlerRegister()
LOGDATA($LEVEL, "ETSSO WIZARD DEBUG","starting web page controls.")
;$oIE = _IEAttach(GUICtrlRead($logontitle,1))
;Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc")
LOGDATA($LEVEL, "ETSSO WIZARD DEBUG","Getting web page controls table.")
$oInputs = _IETagNameGetCollection($oIE, "input")
LOGDATA($LEVEL, "ETSSO WIZARD DEBUG","Adding each control to combobox drop down.")
For $oInput In $oInputs
;ConsoleWrite($oInput.name&@CRLF)
;LOGDATA($LEVEL, "ETSSO WIZARD DEBUG","found control: "&$oInput.name)
GUICtrlSetData($WizAppLogonCtrl, $oInput.name,"") ; add other item
GUICtrlSetData($WizAppPasswdCtrl, $oInput.name,"") ; add other item
GUICtrlSetData($WizAppSubmitCtrl, $oInput.name,"") ; add other item
Next
_IEErrorHandlerDeRegister()
Return
EndFunc

ie.au3 code where the error is called ? I do not mind the errors but I do not want the script to error out

Func _IETagNameGetCollection(ByRef $o_object, $s_TagName, $i_index = -1)
If Not IsObj($o_object) Then
__IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidDataType")
Return SetError($_IEStatus_InvalidDataType, 1, 0)
EndIf
;
If Not __IEIsObjType($o_object, "browserdom") Then
__IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidObjectType")
Return SetError($_IEStatus_InvalidObjectType, 1, 0)
EndIf
Local $oTemp
If __IEIsObjType($o_object, "documentcontainer") Then
$oTemp = _IEDocGetObj($o_object)
Else
$oTemp = $o_object
EndIf$i_index = Number($i_index)
Select
Case $i_index = -1
Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName).length, _
     $oTemp.GetElementsByTagName($s_TagName))
Case $i_index > -1 And $i_index < $oTemp.GetElementsByTagName($s_TagName).length
Return SetError($_IEStatus_Success, $oTemp.GetElementsByTagName($s_TagName).length, _
     $oTemp.GetElementsByTagName($s_TagName).item($i_index))
Case $i_index < -1
__IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_InvalidValue", "$i_index < -1")
Return SetError($_IEStatus_InvalidValue, 3, 0)
Case Else
__IEErrorNotify("Error", "_IETagNameGetCollection", "$_IEStatus_NoMatch")
Return SetError($_IEStatus_NoMatch, 0, 0) ; Could be caused by parameter 2, 3 or both
EndSelect
EndFunc ;==>_IETagNameGetCollection
Edited by RogFleming
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...