Sign in to follow this  
Followers 0
Skitty

Getting an error with arrays...

27 posts in this topic

"Array variable has incorrect number of subscripts or subscript dimension range exceeded."

What are the default subscript limits?

What are sub scripts?

I can't post the code since its 3018 lines, too long to post here and only works on my pc so it isn't relevant anyway...

But I keep getting this damn error after adding some more items to an array..


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Usually it's a problem with your index exceeding the number of elements in the array.

Let's say you have an array $aArray[10]. As the elements start with 0, you can access them with an index from 0 to 9. If you try to access element 10 you get the described error.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

I suggest you read this before you attempt to use arrays again. You need to find out how they work, and you obviously missed that part of the tutorials.


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

Usually it's a problem with your index exceeding the number of elements in the array.

Let's say you have an array $aArray[10]. As the elements start with 0, you can access them with an index from 0 to 9. If you try to access element 10 you get the described error.

Thanks, thats exactly whats wrong.

It's a little counter var thats interfering with the array during a Do - Until func...


Things that I've done..

Icon Resource Editor: icon resource editor 

AutoIt Piano: a piano

AutoIt Unlocker: unlocks files when you want to delete them

Colorful tooltips: a wrapper for the tool tips UDF

Rouge GoogleBot: a full screen animation

ASciTE text editor: a text editor written in autoit

Warning: Posts by this user are subject to change or may disappear without notice.

Share this post


Link to post
Share on other sites

Thanks, thats exactly whats wrong.

It's a little counter var thats interfering with the array during a Do - Until func...

Is there a way to catch this error, tried (ObjEvent("AutoIt.Error","ErrorFunc")) it didn't work.

Share this post


Link to post
Share on other sites

As for the limitations of arrays in AutoIt:

"You can use up to 64 dimensions in an Array. The total number of entries cannot be greater than 2^24 (16 777 216)."

:)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

When such error occurs, is it possible to catch it

Share this post


Link to post
Share on other sites

#include <array.au3>

Dim $aArray[5]
$aArray[0] = 1
$aArray[1] = 2
$aArray[2] = 3
$aArray[3] = 4
$aArray[4] = 5

for $i = 0 to 5

    If $i > ubound ($aArray) - 1 Then
        msgbox (0, '' , "number of array elements exceeded")
        exitloop
    EndIf

    msgbox (0, '' , $aArray[$i])

    Next


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#include <array.au3>

Dim $aArray[5]
$aArray[0] = 1
$aArray[1] = 2
$aArray[2] = 3
$aArray[3] = 4
$aArray[4] = 5

for $i = 0 to 5

    If $i > ubound ($aArray) - 1 Then
        msgbox (0, '' , "number of array elements exceeded")
        exitloop
    EndIf

    msgbox (0, '' , $aArray[$i])

    Next

I thought about something like that but honestly I was too lazy to write. :)

And maybe it isn't exactly what "heidenheim" wants... I'd guess he's looking for a global function to catch those errors. :)


Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]

Share this post


Link to post
Share on other sites

I thought about something like that but honestly I was too lazy to write. :)

And maybe it isn't exactly what "heidenheim" wants... I'd guess he's looking for a global function to catch those errors. :)

Exact, i'm not looking for a way to avoid the error, but to catch it when occurs. I just want to exit the program when it happens, preventing the annoying message box: (Error: Array variable...)

Share this post


Link to post
Share on other sites

and that would be different from commenting out the msgbox and leaving just the exitloop?


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

and that would be different from commenting out the msgbox and leaving just the exitloop?

By default Autoit generates the message box when this error occurs,There's no need to use the code posted by Hannes123.

Share this post


Link to post
Share on other sites

Seriously, yer serious?

#include <array.au3>

Dim $aArray[5]
$aArray[0] = 1
$aArray[1] = 2
$aArray[2] = 3
$aArray[3] = 4
$aArray[4] = 5

for $i = 0 to 5

    If $i > ubound ($aArray) - 1 Then
       ; msgbox (0, '' , "number of array elements exceeded")
        exitloop
    EndIf

    msgbox (0, '' , $aArray[$i])

    Next

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

I don't think that's the messagebox he means, but rather the one triggered by AutoIt's default error handler. I'm not sure there is much you can do about that one though.

Share this post


Link to post
Share on other sites

maybe im dense? but I dont get that message when i have the If statement there.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

Exact, i'm not looking for a way to avoid the error, but to catch it when occurs.

As in "default behavior without the added check for each array operation in the script".

Imo it's a pretty horrible idea, because you will end up with arrays that do not contain the data you expect them to, but the resulting crash will often be in a completely different part of the script, making debugging an absolute pain.

(Unless you where to keep a log of these errors and can reliably get that log from the clients PC's... etc. Personally I'm not a fan.)

In any case I think that's what he's asking for and afaik it's not possible to catch anything but com errors and handle the return/@error/@Extended values for functions.

Share this post


Link to post
Share on other sites

Exact, i'm not looking for a way to avoid the error, but to catch it when occurs. I just want to exit the program when it happens, preventing the annoying message box: (Error: Array variable...)

The whole point is to avoid the errors in the first place. If you're looking to make it so that the script never crashes then you're either going to have to code it correctly, or only run it in situations that you're sure will never cause it to crash. Bugs happen, but with proper testing you can eliminate most of them. Sometimes you have to try to be smarter than the users of the scripts, or let others test your scripts before you release them so they can help find situations you didn't think about and find ways to code around them.

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

Thanks everyone for the advices, the thing is the script runs 24h a day and according to murphy's law no matter how sophisticated the code, if there's a tiny little chance that it crashes, it will crash.

I'll try to handle all the cases and make a log

Share this post


Link to post
Share on other sites

If you need your script to be up and running 24 hrs you could write a second script to check every x seconds if the main script is still running. If not restart it or send an email or do whatever you want ...


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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
Sign in to follow this  
Followers 0