Jump to content
nooneclose

[SOLVED] A way to not end a script when "Subscript used on non-accessible variable" occurs?

Recommended Posts

Morning, I am wondering is there is a way to prevent a script from ending/crashing when a "Subscript used on non-accessible variable" error occurs? 

Here is some of my code:

$aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0)
    If @error Then
        Sleep(2000)
        LoopUnreadEmails()
        ;Exit MsgBox(48, "", "@error = " & @error & ", @extended: " & @extended & " at line: " & @ScriptLineNumber)
    EndIf

Error Msg:

(371) : ==> Subscript used on non-accessible variable.:
$aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0)
$aItems = _OL_ItemFind($oOutlook, $mFolder^ ERROR

I know that error occurs very rarely and at random. But like with most errors "in this case" I can use recursion to fix it. 

I just recall the function and it will and has fixed itself. But this "Subscript used on non-accessible variable" just ends the script.

Like I said before, is there a way to allow the script to keep running or call a function when this error occurs instead of just ending?   

Edited by nooneclose
problem solved to the best of our ability

Share this post


Link to post
Share on other sites

Do proper error checking before sending the array array to the function. Make sure that first it's an array, and second has the correct number of subscripts, then use the function with the array. Otherwise you're hiding an error that you won't know about and are just obfuscating improper error checking.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

@BrewManNH Something like this?

Func ScanInvaildEmails()

    Local $mFolder = _OL_FolderAccess($oOutlook, "Inbox")
    If IsArray($mFolder) Then
        Local $iRows = UBound($mFolder, $UBOUND_ROWS)
        If $iRows >= 2 Then
            ; It worked, do nothing
        Else
            Sleep(2000)
            ScanInvaildEmails()
        EndIf
    Else
        Sleep(2000)
        ScanInvaildEmails()
    EndIf
    
EndFunc

 

Edited by nooneclose
Spacing in code bugged me

Share this post


Link to post
Share on other sites

No, you're using recursion where you shouldn't be. You can put the whole thing inside a loop and never call the same function over and over. You have no way to leave this either so it will continue to recurse until it errors out, if left running long enough. Here's the proper way to go about it without the recursion.

Func ScanInvaildEmails()
     While 1
          Local $mFolder = _OL_FolderAccess($oOutlook, "Inbox")
          If IsArray($mFolder) Then
               Local $iRows = UBound($mFolder, $UBOUND_ROWS)
               If $iRows >= 2 Then
                    ; It worked, do nothing
               Else
                    Sleep(2000)
;~                ScanInvaildEmails()
               EndIf
          Else
               Sleep(2000)
;~           ScanInvaildEmails()
          EndIf
     WEnd
EndFunc   ;==>ScanInvaildEmails

You'll just need someway to exit this loop, the same as with your script, it's an endless loop with no way to exit it.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I want it to exit if it is an array and if it does contain the correct number of subscripts. If it does not then I want it to try again because it should be.  

Func ScanInvaildEmails()
     While 1
          Local $mFolder = _OL_FolderAccess($oOutlook, "Inbox")
          If IsArray($mFolder) Then
               Local $iRows = UBound($mFolder, $UBOUND_ROWS)
               If $iRows >= 2 Then
                    ; It worked, Go to next function
                    ExitLoop 
               Else
                    Sleep(2000)
;~                ScanInvaildEmails()
               EndIf
          Else
               Sleep(2000)
;~           ScanInvaildEmails()
          EndIf
     WEnd
EndFunc   ;==>ScanInvaildEmails

This will try until its a proper Array with the correct subscripts and move on if I add Exitloop correct? 

Share this post


Link to post
Share on other sites

@BrewManNH Some of my emails were processed more than once. (the same email 2-3 times)

could this code be the cause? (is it somehow adding the same email multiple times to the array?)

; Find all vaild E-mails in the inbox
    While 1
        $aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0)
        If IsArray($aItems) Then
            ; It worked, Exit loop
            ConsoleWrite(@CRLF & "Array created" & " at line: " & @ScriptLineNumber & @CRLF)
            Exitloop
        Else
            Sleep(2000)
            ConsoleWrite("Error: No Array created" & " at line: " & @ScriptLineNumber & @CRLF)
        EndIf
    WEnd

 

Share this post


Link to post
Share on other sites

@genius257 I do not understand what your code does or how it would help loop until an Array was successfully created. I have been using while loops they have worked very well so far. 

Edited by nooneclose
grammar

Share this post


Link to post
Share on other sites

I assume you are trying to process new mails. In this case I suggest to use events. Means: A function in your script gets triggered as soon as a new mail arrives.
Please see the example scripts section in my signature.
Edit: Added an updated example fot the NewMailEx event today.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2020-07-21 - Version 1.5.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2020-06-27 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (NEW 2020-06-27 - Version 1.3.2.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 (2017-06-06 - Version 0.0.5.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

 

Share this post


Link to post
Share on other sites

@nooneclose

Execute sets the @error flag to non zero on failure.

so:

While 1
    $value = Execute("$mFolder[1]")
    If @error <> 0 Then
        Sleep(1000)
        ContinueLoop
    EndIf
    $aItems = _OL_ItemFind($oOutlook, $mFolder[1], $olMail, "[UnRead]=True", "Subject", "Maintenance Request", "EntryID,Subject", "", 0)
WEnd

I assume you'll use @water's solution, but it's always good with options

Share this post


Link to post
Share on other sites

Of course fixing the root cause of a potential error is much, really much better than trying to circumvent the consequences of an error.

The former is correct code, the latter is duck tape on a crack in a concrete wall.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
12 hours ago, jchd said:

Of course fixing the root cause of a potential error is much, really much better than trying to circumvent the consequences of an error.

The former is correct code, the latter is duck tape on a crack in a concrete wall.

@jchd Which former code? Also, my script needs to runs 24/7. Hence the original reason why I created this thread. I needed a way to stop the script when stops on Autoit Errors. The only way I have found so far is by creating a disgusting amount of Error checking and if that does not work calling the function again (this eventually forces it to correct itself). I know that it is not a good practice to force code to work if it has problems. However, when you have to make it run 24/7 it's a bit different.      

Share this post


Link to post
Share on other sites

"The former" refers to "fixing the root cause".

A software having to run reliably 24/7 is an imperative reason to code it robustly in the first place and catch all the potential errors and handle them gracefully.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
6 minutes ago, jchd said:

"The former" refers to "fixing the root cause".

A software having to run reliably 24/7 is an imperative reason to code it robustly in the first place and catch all the potential errors and handle them gracefully.

Yes, I would love to program it that way. However, since I do not know all of Autoit syntax and functions it is harder for me to do so. Also with people who just comment without giving any real help just keep making it difficult to refine not just my code but for anyone who seeks help. I greatly appreciate the people who take time out of their day to help me. It is annoying though when some people comment for comment's sake.  Whether it was to argue or to actually help. If one wants to help but is not clear and or does not contribute to solving the problem then what's the point? I understand where you are coming from but unless you can show me examples or teach me how to do better how can I improve? 

Share this post


Link to post
Share on other sites
34 minutes ago, nooneclose said:

how can I improve?

First by studying AutoIt syntax and functions you don't already know and master, at least the parts that relate to your goal (processing mails).
Then by following advices that were given by @BrewManNH and @water.

I was just stressing that the more important a software is in practice the more care must be devoted to its conception.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

I guess you need to learn Autoit And I suggest reading the users manual for anything you “don’t know”

 

We’re not here for you to order up code from we are here to assist you with the code you’ve written

 

Giving you code isn’t helping you it’s holding you back

Edited by Earthshine

My resources are limited. You must ask the right questions

 

Share this post


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.

  • Similar Content

    • By Jahar
      I have an AutoIT script It monitors 2 websites for content that applys to me and the services that I provide. One site is : www.Freelancer.com The other: www.PeoplePerHour.com Both sites publish new jobs on their site hourly or so. My AutoIT app, will view those sites and present new jobs to me in a grid that pops up on my screen. Lately, the app has stopped showing me any jobs from PeoplePerHour.
       
      For freelancer.com,  Inetget is giving full html but for peopleperhour, now its not coming.
      Func _CheckPPH()
          Local Static $hTimer = 0
          Local Static $hDownload = 0
          Local $aTitlesandUrls = 0
          Local Static $sTempFile = ""
          If $hTimer = 0 Then $hTimer = TimerInit()
          If $hDownload = 0 Then
              $sTempFile = _WinAPI_GetTempFileName(@TempDir)
              ConsoleWrite("Checking PPH..." & @CRLF)
              ConsoleWrite(">Downloading..." & @CRLF)
      ;~         $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD, $INET_DOWNLOADBACKGROUND)
              $hDownload = InetGet("http://www.peopleperhour.com/freelance-jobs", $sTempFile, $INET_FORCERELOAD)
      ;~         Return 0
          EndIf
      ;~     Sleep(30)
      ;~     Local $isCompleted = InetGetInfo($hDownload, $INET_DOWNLOADCOMPLETE)
      ;~     Local $isError = InetGetInfo($hDownload, $INET_DOWNLOADERROR)
      ;~     Sleep(30)
      ;~     If TimerDiff($hTimer) > 3000 And $isError Then
      ;~         ConsoleWrite("!PPH Fail" & @CRLF)
      ;~         InetClose($hDownload)
      ;~         $hDownload = 0
      ;~         Return 0
      ;~     EndIf
      ;~     Sleep(30)
          Local $Show = 0
      ;~     If TimerDiff($hTimer) > 3000 And $isCompleted Then
          If $hDownload > 0 Then
              ConsoleWrite("+Downloaded..." & @CRLF)
              Local $sPPHHtml = FileRead($sTempFile)
              $aTitlesandUrls = _StringBetween($sPPHHtml, '"title">' & @LF, 'time>')
      ;~         _ArrayDisplay($aTitlesandUrls)
              Local $aPPH[0][4]
              Local $sTitle = ""
              Local $sUrl = ""
              Local $sID = ""
              Local $sDate = ""
              Local $iRet=0
              Sleep(30)
              For $i = 0 To UBound($aTitlesandUrls) - 1
                  $sTitle = _StringBetween($aTitlesandUrls[$i], '<a title="', '" class')
                  $sUrl = _StringBetween($aTitlesandUrls[$i], 'href="', '">')
                  $sDate = _GetDate($aTitlesandUrls[$i])
                  If IsArray($sTitle) And IsArray($sUrl) Then
                      $sID = _GetID($sUrl[0])
      ;~                 _ArrayAdd($aPPH, $sDate & "|" & $sTitle[0] & "|" & $sUrl[0] & "|" & $sID)
                      $iRet = _BuildPopupsPPH($sID, $sDate, "PPH: " & $sTitle[0], $sUrl[0])
                      If $iRet Then $Show+=1
                  EndIf
              Next
              Sleep(30)
      ;~         If $Show > 0 Then ShowLatestJobs()
      ;~         _ArrayDisplay($aPPH)
              FileDelete($sTempFile)
              InetClose($hDownload)
              $hDownload = 0
              $hTimer = 0
              Return $Show
          EndIf
          Sleep(30)
      EndFunc   ;==>_CheckPPH
    • By malicioussoap
      back when I was still doing autohotkey you could write (in code) spanisha::á
      and whenever you were in google docs or notepad you could type (in the document) spanisha  and it instantly turns it into á 
      I tried doing this in autoit, here's what I have so far (my entire code so if this language requires a main function or a return/exit to function properly please let me know):
      ;is this a proper comment? HotKeySet ( "spanisha" , "SendAltered" ) Func SendAltered() Send("á", flag = 0); EndFunc I assume that autoit follows a sort of contemporary hotkey pressing model where you have to hold all keys at the same time? which makes this impossible. So
      I'm wondering if anyone has a workaround for this? or maybe an alternative to HotKeySet()
      I have a vague memory of someone saying that doing something like spanisha:á would work. I don't know if I'm slightly off syntax but this doesn't work.
      Also I tried doing 
      ;is this a proper comment? ;HotKeySet ( "a" , "SendAltered" ) ;spanisha::á Func SendAltered() Send("á"); EndFunc just to try and debug,
      I'm also wondering if my approach is fundamentally wrong since HotKeySet() was made for something like !^A. Or if Send() is syntactically wrong.
      I'm also noticing on these forums that specifying installation is important so to whom it may concern I downloaded both installers, editor and main files. Although I'm about to be real mad if the editor installation makes a difference.
    • By shelly
      I have to press tab to reach a selected button then double click on that
      Here's my script but its not working:
      WinActivate("Policy Decisions -- Webpage Dialog","")
      Sleep(3000)
      Send("{TAB}")
      Send("{TAB}")
      Send("{TAB}")                    // at this point its working according to my need  but double click is not working
      Mouseclick("Left",510, 320, 2, 0)

    • By TheDcoder
      See this thread for info:
    • By nooneclose
      Why can I not click on either of my input fields?
      #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 730, 437, 192, 124) ;GUISetFont(14, 800, 0, "MS Sans Serif") GUISetBkColor(0xC0DCC0) Global $Label1 = GUICtrlCreateLabel("Enter your Password. UserName is auto filled", 62, 40, 604, 41, $SS_CENTER) GUICtrlSetFont(-1, 26, 800, 0, "MS Sans Serif") Global $Label2 = GUICtrlCreateLabel("User Name:", 120, 130, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Label3 = GUICtrlCreateLabel("Password:", 135, 210, 604, 31, $SS_LEFT) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") Global $Input1 = GUICtrlCreateInput(@UserName, 274, 130, 185, 32) GUICtrlSetFont(-1, 14, 800, 1, "MS Sans Serif") Global $Input2 = GUICtrlCreateInput("Password", 274, 210, 185, 32, $ES_PASSWORD) GUICtrlSetFont(-1, 14, 800, 0, "MS Sans Serif") Global $OK = GUICtrlCreateButton("OK", 274, 270, 185, 57) GUICtrlSetFont(-1, 20, 800, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $OK Global $UserName = GUICtrlRead($Input1) Global $PassWord = GUICtrlRead($Input2) ExitLoop EndSwitch WEnd ; Delete the GUI window GUIDelete()  
×
×
  • Create New...