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 2019-10-24 - Version 1.4.14.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2019-11-30 - Version 1.4.0.0) - Download - General Help & Support - Example Scripts - Wiki
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 (NEW 2019-12-03 - Version 1.5.1.0) - Download - General Help & Support - Wiki

Tutorials:
ADO - 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

  • Similar Content

    • By nooneclose
      Good morning, I am trying to figure out if it is possible to check if these invoice lines exist or not. 
      Here are the table and column name: INVOICELINE.INVOICELINENUM (a required field if created)
      Here is a picture of what I am talking about. (Do not worry about security. the picture is from a demo test site so all information is fake)
       
      is there any way to check if these fields exist or not? (they do not exist unless the user clicks on "New Row")
      Example: line 11 does not exist right now. How would I go about to see if it did or not? 
      This is what I have so far:
      SELECT DISTINCT iv.invoicenum, iv.description FROM invoice AS iv JOIN invoiceline AS ivl ON iv.invoicenum = ivl.invoicenum AND iv.siteid = ivl.siteid /* = 'nothing' and yet somehow not null? */ WHERE iv.invoicenum NOT IN (SELECT invoicelinenum FROM invoiceline WHERE invoicelinenum IS NOT NULL) I get 0 results where I should get more than 0. 
    • By Kruxe
      Hello Everyone,
      I am very green when it comes to AutoIT, I have recently started using it to automate a job that i perform using MS Excel and that is working great. Recently I have been faced with a challenge I which i need to copy a specific set of lines from one .txt file and past them, overwriting a specific set of lines in a different .txt file. I honestly have no clue how I can copy the specified lines and transfer them. What functions / commands could I use and how could I lay them out I AutoIT? Any and all help will be appreciated. 
      Thanks!
      Kruxe
    • By Saravanan2213
      Hi everyone,
      i just need your help. i have script for cleaning browsing history and other unwanted file but the problem is i don't want to see the GUI i have attached below. It should not show anything on the screen. is it possible to do it in autoit. thanks in advance.
       
      So for i have tried flag
      Run("rundll32.exe InetCpl.cpl,ClearMyTracksByProcess 255", "", @SW_HIDE)
      @SW_DISABLE
       
      Looking forward your help.........

    • By cptHark
      Hello I want to conect to a Network with DriveMapAdd.
      This worked just fine but when you restart the Computer the Mapped drive is gone.
      So i used the persistent mapping flag and that seemed to work, too.
      However when the Computer is restarted I cant connect to the Network because it doesnt remember the Username and password I ave it the first time.
      How do I fix this?
      My Code:Func
      setdrivem()
          DriveMapAdd("M:", GUICtrlRead($driveM),1, GUICtrlRead($netzuser),GUICtrlRead($netzpassword) )
      EndFunc
      $netzuser and $netzpassword are set earlier in the gui and it works right after executing the script but i want it to stay connected
    • By max23ed
      Hi,  i'm recording a setup for a program using mouse clicks , however, the problem is when the setup installs (the progress bar showing) the auto generated script by the recorder will not have a winwait() or sleep() to click the "finish" button when the setup is completed. is there anyway to  do that automatically?
×
×
  • Create New...