Skitty Posted February 23, 2011 Share Posted February 23, 2011 "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.. Link to comment Share on other sites More sharing options...
water Posted February 23, 2011 Share Posted February 23, 2011 (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 February 24, 2011 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
BrewManNH Posted February 24, 2011 Share Posted February 24, 2011 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 GudeHow 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 Link to comment Share on other sites More sharing options...
Skitty Posted February 24, 2011 Author Share Posted February 24, 2011 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... Link to comment Share on other sites More sharing options...
hohenheim Posted March 17, 2011 Share Posted March 17, 2011 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. Link to comment Share on other sites More sharing options...
hannes08 Posted March 17, 2011 Share Posted March 17, 2011 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] Link to comment Share on other sites More sharing options...
hohenheim Posted March 17, 2011 Share Posted March 17, 2011 When such error occurs, is it possible to catch it Link to comment Share on other sites More sharing options...
iamtheky Posted March 17, 2011 Share Posted March 17, 2011 #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 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
hannes08 Posted March 17, 2011 Share Posted March 17, 2011 #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] Link to comment Share on other sites More sharing options...
hohenheim Posted March 17, 2011 Share Posted March 17, 2011 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...) Link to comment Share on other sites More sharing options...
iamtheky Posted March 17, 2011 Share Posted March 17, 2011 and that would be different from commenting out the msgbox and leaving just the exitloop? ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
hohenheim Posted March 18, 2011 Share Posted March 18, 2011 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. Link to comment Share on other sites More sharing options...
iamtheky Posted March 18, 2011 Share Posted March 18, 2011 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 ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Tvern Posted March 18, 2011 Share Posted March 18, 2011 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. Link to comment Share on other sites More sharing options...
iamtheky Posted March 18, 2011 Share Posted March 18, 2011 maybe im dense? but I dont get that message when i have the If statement there. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
Tvern Posted March 18, 2011 Share Posted March 18, 2011 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. Link to comment Share on other sites More sharing options...
BrewManNH Posted March 18, 2011 Share Posted March 18, 2011 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 GudeHow 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 Link to comment Share on other sites More sharing options...
hohenheim Posted March 18, 2011 Share Posted March 18, 2011 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 Link to comment Share on other sites More sharing options...
water Posted March 18, 2011 Share Posted March 18, 2011 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
AdmiralAlkex Posted March 18, 2011 Share Posted March 18, 2011 @hohenheim You can use /ErrorStdOut, see helpfile. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now