Jump to content
Sign in to follow this  
MerleHaggard

Array Exceeding Error

Recommended Posts

MerleHaggard

Im gathering 10 pictures per round via IE and storing them into a picture folder. Im running an outside program which resizes the original 10 pictures (therefore replacing them) and produces one thumbnail of each picture w/ _small as the end of the filename. (Ex. Original: bears.jpg, Thumbnail: bears_small.jpg). I use this code to search for files in the array containing the _small string. Then it takes the file it found, and moves it into a different folder, eventually leaving the first 10 (now resized). It recreates the array, finds the next fileand so on until there are no _small strings left in the array. I first thought it was erroring in the cases where there were less than 10 pictures in the folder (if IE messed up), but I changed the code to add the If statements. This morning, it moved all 10 of the pictures perfectly, but never went on to the next part of the script, and errored out w/ the array exceed substring. Error. Ive been after this for a couple of days, and I have read the array section that udep (spelling?) refers people to. Any ideas?

P.S. this is my first autoit script and Ive only done C++ (and failed the one class) never done scripting before, so be nice.

CODE
$sCount = 0

$iStart = 0

$iEnd = 0

$iCaseSense = 0

$fPartialSearch = False

$sSource = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$" & "\$thumbname$"

$sDest = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$" & "\$thumbname$"

$array = _FileListToArray("C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$")

Do

$vWhat2Find = "_small"

$ArraySearch = _ArraySearch($array, $vWhat2Find, $iStart = 0, $iEnd = 0, $iCaseSense = 0, $fPartialSearch = False)

$thumbname = $array["$ArraySearch$"]

If $ArraySearch = 1 Then

ExitLoop

Else If $ArraySearch = 6 Then

ExitLoop

EndIf

$sSource = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$" & "\$thumbname$"

$sDest = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$" & "\$thumbname$"

FileMove($sSource, $sDest)

$sCount = $sCount + 1

Until $sCount = 9

Share this post


Link to post
Share on other sites
SadBunny

Im gathering 10 pictures per round via IE and storing them into a picture folder. Im running an outside program which resizes the original 10 pictures (therefore replacing them) and produces one thumbnail of each picture w/ _small as the end of the filename. (Ex. Original: bears.jpg, Thumbnail: bears_small.jpg). I use this code to search for files in the array containing the _small string. Then it takes the file it found, and moves it into a different folder, eventually leaving the first 10 (now resized). It recreates the array, finds the next fileand so on until there are no _small strings left in the array. I first thought it was erroring in the cases where there were less than 10 pictures in the folder (if IE messed up), but I changed the code to add the If statements. This morning, it moved all 10 of the pictures perfectly, but never went on to the next part of the script, and errored out w/ the array exceed substring. Error. Ive been after this for a couple of days, and I have read the array section that udep (spelling?) refers people to. Any ideas?

Well there is a couple of weird things in your code...

1)

$someVar$ within a string? Seems a bit useless...

2)

$ArraySearch = _ArraySearch($array, $vWhat2Find, $iStart = 0, $iEnd = 0, $iCaseSense = 0, $fPartialSearch = False)oÝ÷ Øb±·­µêí¡Æ¥Øb²X¤y«­¢+ØÀÌØíÉÉåMÉ ô}ÉÉåMÉ  ÀÌØíÉÉä°ÀÌØíÙ]¡ÐÉ¥¹°À°À°À°±Í¤oÝ÷ Û{azåÊ«¨¶·«¨¶ènW¦!Ê.×âÖ®¶­sbb33c·FVÖ&æÖRÒb33c¶'&²gV÷C²b33c´'&6V&6b33c²gV÷Cµ

You declare a variable and you try to put an element from an array called '$array' into that. This is not a problem, but what IS a problem is that the '$array' array was not created yet, and that the [] need an element number (like $var = $someArray[2] or $var = $someArray[$reqElementNumber]).

Hope this helps...


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
Sokko

1)

$someVar$ within a string? Seems a bit useless...

He is probably using ExpandVarStrings, and from the looks of your #3, he got a bit confused and tried to use the same technique to access an element of an array.

Share this post


Link to post
Share on other sites
MerleHaggard

Thanks for the quick response Bunny

1) With regards to the variable in a string: The file paths are dependent upon the current status of the program as a whole. Therefore it will navigate to the desired set or round Im on. Basically Im pulling 10 images from a site based on a keyword, and the keyword changes every time the loop runs. If Im going about this the wrong way, please feel free to point me in a better direction

2) Makes sensethank you

3) Isnt the $array declared above in the _FileListToArray ? If not, would I change my code to look like this?

CODE
$sCount = 0

$iStart = 0

$iEnd = 0

$iCaseSense = 0

$fPartialSearch = False

$sSource = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$" & "\$thumbname$"

$sDest = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$" & "\$thumbname$"

Dim $array[22]

$array = _FileListToArray("C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$")

Do

$vWhat2Find = "_small"

$ArraySearch = _ArraySearch($array, $vWhat2Find, $iStart = 0, $iEnd = 0, $iCaseSense = 0, $fPartialSearch = False)

$thumbname = $array["$ArraySearch$"]

If $ArraySearch = 1 Then

ExitLoop

Else If $ArraySearch = 6 Then

ExitLoop

EndIf

$sSource = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$" & "\$thumbname$"

$sDest = "C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$" & "\$thumbname$"

FileMove($sSource, $sDest)

$sCount = $sCount + 1

Until $sCount = 9

Where I've declared '$array' before using _Filelisttoarray ?

Sokko - I am using expvarstrings - and I will probably take the quotes off and the $, but if that was incorrect, howcome it was able to move the files over correct prior to giving the error? I'm not contradicting you on purpose, just inquiring so that I can understand better

Share this post


Link to post
Share on other sites
SadBunny

He is probably using ExpandVarStrings, and from the looks of your #3, he got a bit confused and tried to use the same technique to access an element of an array.

Well that explains!

I must confess I did not even know that option! :"> :"> :"> :"> :"> :"> :"> :"> :"> :"> :"> :">

I use Opt() a lot, I would have thought that I pretty much know most useful Opt() 's by now after about 6 months of AutoItting :shocked:

I totally can't believe that I did not notice this before! Thank you so very much for accidentally being the first to point me there :P

You see, especially now this is an INCREDIBLY useful function for me, seeing as that starting next week I will be translating some big scripts and thus will need to change the location of where the variables were concatenated between strings to keep international grammar intact. It was a total nightmare having to go through all the code I would never have expected ever to have to translate! I actually started working TODAY on a code-processing script that did almost exactly what this Opt() does, only with different chars, to work around this.

So knowing this probably just saved me hours of work and reinventing the wheel, thanks!

BTW And it has noted me that I need to read the AutoIt help file religiously for 30 minutes before going to bed instead of Ludlum... :(


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
SadBunny

3) Isnt the $array declared above in the _FileListToArray ? If not, would I change my code to look like this?

Where I've declared '$array' before using _Filelisttoarray ?

Yes, you're right, so sorry, I answered too quickly. Please disregard point 1 from my previous post. :">

Now I looked at it better, and ofcourse you did create $array. Only, I tried it and got an error because <stupid me> ... The directory specified does not exist for me!! - DuH - That's why I thought the $array was not created. Had I looked at the error I got and the code a bit better, I would not have said this.

Furthermore, I went ahead and tested this newly found ExpandVarStrings using the following code. Like I would expect your code to do too, it accepts the $var1$ as the element number just fine, so that point 3 of me didn't make sense either... Must pay more attention in the future... :shocked:

Opt("ExpandVarStrings",1)
Dim $a[3]
$a[1]="test2"
$var1 = 1
MsgBox(0,"test",$a["$var1$"])

Since this works fine but your code gives an array error, maybe still the _fileListToArray fails somewhere, please try to catch the @error to see if something went wrong after the _FileListToArray operation.

BTW you should only have to do Dim $a[22] or something before putting something in it if you have the Opt(MustDeclareVars,1) turned on.

Oh, and PS: thanks for leading me to the Opt() option... As I said above... :">


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
MerleHaggard

Thanks, I will get the exact error tonight, but I do remember the error pointing to the

["$ArraySearch$"] box when the "exceeded range of substrings..." error occurs...

There is a second error that shows up sometimes that actually points to the <Array.UDF> File I have included, that one baffles the crap out of me, but it doesn't happen often. Again, I will get the exact error when I get home this evening

Share this post


Link to post
Share on other sites
SadBunny

Thanks, I will get the exact error tonight, but I do remember the error pointing to the

["$ArraySearch$"] box when the "exceeded range of substrings..." error occurs...

There is a second error that shows up sometimes that actually points to the <Array.UDF> File I have included, that one baffles the crap out of me, but it doesn't happen often. Again, I will get the exact error when I get home this evening

Just to be sure: I did not mean the error in the console where the ^ points (though that's always useful to have too). I meant @error catching as in:

$array = _FileListToArray("C:\Documents and Settings\Arlin\Desktop\SS\Round $round$\Set $set$\$sReadCell$")

if @error then msgbox(0,"error","Error in _FileListToArray. The @error code set by _FileListToArray was: "&$error)

(Don't know if you know, but many functions set the @error macro to return some non-zero number after a function has failed to do something it was told to. Check the help files for instance for _FileListToArray to see what the different @error codes mean.)


Roses are FF0000, violets are 0000FF... All my base are belong to you.

Share this post


Link to post
Share on other sites
MerleHaggard

Thanks for your input, I tweaked it a bit based on suggestions, but the main issue apparently...was that "partial search" was set to false. I made it true, and it's working like a beauty, except for when IE times out...but that's another issue altogether.

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  

×