Jump to content

Ignore "Variable must be of type "Object"" Errors


Recommended Posts

Hello AutoIT gang,

I am in desperate need of help. We just upgraded AutoIT, however it seems the old one let these things slide, and I need to adjust my script. This script is massive (5000 lines) and the write took several months, so for sake of argument, let's just say I want to completely ignore any unfound object errors, just as the last version did, or maybe catch the specific ones and allow the script to continue. I can use other users' information to catch the errors, but getting the script to continue has been quite the challenge, I can't even put in an IF statement with the error, because the instant it can't find the object, the whole script cancels. The issue is, this script needs to call on several objects and see which responds to know which version of SAP it is working with, as SAP updates their object names often, so I've been calling a few different possible objects and getting their returns.

For example, my script will fail at this line.. I can put an IF statement before it, after, whatever, I cannot seem to get past this error.

$sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7

 

A couple of the errors I'm getting are either - "Variable must be of type "Object" or "The requested action with this object has failed" and using another user's function was able to get the description "The control could not be found by id.".

 

Please let me know.

Edited by runinfromjason
Link to post
Share on other sites
Global $oMyError = ObjEvent("AutoIt.Error", "_ADDoError") ; error handler einrichten

Func _ADDoError() ; Custom Error Handler
    Local $HexNumber = Hex($oMyError.number, 8)
    ConsoleWrite($HexNumer & @crlf)
    Return
EndFunc   ;==>_ADDoError

this should do the job. It's something like "on error continue" 🤪

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

Link to post
Share on other sites

you could also try wrapping the whole statement inside an Execute () by passing it as a string; something like this:

Execute('$sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7')

and checking @error if you need to know if the command you passed was successful or if there were any problems. In this way the script should not stop and continue without crashing even in the case of "Variable must be of type" Object "or" The requested action with this object has failed "...

See here for the source of this technique.

Edited by Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites

Like @Marc said.

But if you want a streamlined version, but being able to detect the error use this :

Global $oMyError = ObjEvent("AutoIt.Error", _ErrorHandler)

$obj = ObjCreate("Scripting.Dictionary")
$obj.error()
If @error Then ConsoleWrite ("error found " & Hex(@error) & @CRLF)

Func _ErrorHandler()
EndFunc

 

Link to post
Share on other sites

Thanks for the replies, all great ideas. The execute suggestion might actually work, I'm not sure if I can use variables in there, but I'll definitely look more into that. 

These functions to catch the errors work great for the "The requested action with this object has failed" errors, however, they do not seem to work on the "Variable must be of type Object" errors. Does anyone know why that might be? Shouldn't these catch all object errors?

 

Let's use this one for example..

Global $oMyError = ObjEvent("AutoIt.Error", "_ADDoError") ; error handler einrichten

Func _ADDoError() ; Custom Error Handler
    Local $HexNumber = Hex($oMyError.number, 8)
    ConsoleWrite($HexNumer & @crlf)
    Return
EndFunc   ;==>_ADDoError

It allows the script to continue once it hits the "The requested action with this object has failed" error, however, later the script still fails, now ONLY at the particular error "Variable must be of type "Object".

Link to post
Share on other sites
36 minutes ago, runinfromjason said:

however, they do not seem to work on the "Variable must be of type Object" errors. Does anyone know why that might be? Shouldn't these catch all object errors?

This errors happen when you ignore a previous COM error.
If you try to create an object and it fails you get a COM error. if you ignore this COM error the next statement trying to access the created object (in fact it isn't an object, the variable is undefined) will fail with the mentioned eror message.

Only solution:
The COM error handler needs to decide it the error can be safely ignored or if an error handling action (display an error message, exit the script ...) is needed.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (NEW 2021-07-28 - Version 1.1.0.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
2 hours ago, runinfromjason said:

$sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7

It look's like you've been hit by this bug:

https://www.autoitscript.com/trac/autoit/ticket/3167

To work around the problem in your code, your code should look's like this:

Local $oTemp = $sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]")
$oTemp.caretPosition = 7

instead:

$sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7
Edited by mLipok

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Link to post
Share on other sites
Quote

The COM error handler needs to decide it the error can be safely ignored or if an error handling action (display an error message, exit the script ...) is needed.

This all makes sense, but is there a way to control how it decides what to do with these errors? Using the example above, which I've tried, it is telling the system how to handle the error in the If @error statement.

Global $oMyError = ObjEvent("AutoIt.Error", _ErrorHandler)

$obj = ObjCreate("Scripting.Dictionary")
$obj.error()
If @error Then ConsoleWrite ("error found " & Hex(@error) & @CRLF)

Func _ErrorHandler()
EndFunc

 

Link to post
Share on other sites
.....
Global $oMyError = ObjEvent("AutoIt.Error", _COM_ErrFunc)
.....
_Example()
Func _Example()
    .........
    Local $oTemp = $sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]")
    If @error Then ............
    $oTemp.caretPosition = 7
    If @error Then ............
    .........
EndFunc
.....
; User's COM error function. Will be called if COM error occurs
Func _COM_ErrFunc(ByRef $oError)
        ; Do anything here.
        ConsoleWrite(@ScriptName & " (" & $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   ;==>_ErrFunc
.....

 

Edited by mLipok

Signature beginning:
Please remember: "AutoIt".....  Wondering who uses AutoIt and what it can be used for ?
* GHAPI UDF - modest beginning - communication with GitHub REST API Forum Rules *
Include Dependency Tree (Tool for analyzing script relations)
ADO.au3 UDF     POP3.au3 UDF     XML.au3 UDF    How to use IE.au3  UDF with  AutoIt v3.3.14.x  for other useful stuff click the following button

Spoiler

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind. 

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library *

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) *

PDF Related:How to get reference to PDF object embeded in IE *

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2021-03-17

Link to post
Share on other sites

@error is set to the COM error code (HRESULT) returned by the called function.
Your example returns 0x80020006 - This stands for "DISP_E_UNKNOWNNAME (Unknown name)" and can be found her:
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-erref/705fb797-2175-4a90-b5a3-3918024b10b8

Example:

Global $oMyError = ObjEvent("AutoIt.Error", _ErrorHandler)

$obj = ObjCreate("Scripting.Dictionary")
$obj.error()
If @error = 0x80020006 Then ConsoleWrite("Error - Name not found!" & @CRLF)

Func _ErrorHandler()
EndFunc   ;==>_ErrorHandler

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2021-06-05 - Version 1.5.4.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2021-06-14 - Version 1.6.5.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (NEW 2021-07-28 - Version 1.1.0.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
Task Scheduler (2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - Wiki, WebDriver - Wiki

 

Link to post
Share on other sites
On 4/6/2021 at 12:23 PM, mLipok said:

It look's like you've been hit by this bug:

https://www.autoitscript.com/trac/autoit/ticket/3167

To work around the problem in your code, your code should look's like this:

Local $oTemp = $sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]")
$oTemp.caretPosition = 7

instead:

$sap_session.findById("usr/tblSAPLBD41TCTRL_V_TBDLS/txtV_TBDLS-LOGSYS[0,17]").caretPosition = 7

For anyone wondering, I decided to go this route. It works, it's easy to implement and prevents the errors, exactly where I need them prevented with only a few additional lines of code.

I'd like to thank everyone else for their inputs, it gave me a much better understanding. So far, so good, I'll check back if anything else comes up.

Also, noticed, AutoIT no longer supports "" as output value for a variable. Took me 12 hours to figure out that's also what was wrong, adding to the confusion. I had to change them all to NULL!!

 

Thanks again! Ya'll smart.

Link to post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...