Jump to content

Hello and a problem with a script


Recommended Posts

First of all I wanted to say "Hello :D " I'm new to the forum and AutoIt (but have some excripting experience).

Second, let me apologize for the length of this post, I just wanted to make sure whoever reads this have enough information.

I stumbled upon AutoIt a day ago and this is just amazing, I couldn't stop scripting and finally got everything to work as I wanted except one problem that I'm not sure the logic/reasong for it.

I hope some one can direct me to the right answer or at least the reason for it so I can fix it.

The error the script produces is: "autoit Array Variable subscript badly formatted"

Howevere it still runs the loop...

Since the script is Large and not %100 tidy (that's what happens when you script non stop for one day and going to bed at 4AM :D ) but I'll put, what I believe, is the relevant stuff.

$CountTime=0
$CountURL=0
  For $LineNumber In $ArrayInfoLocation
   For $SearchLineNumber=$LineNumber TO ($LineNumber-6) Step -1
    $ImageURLEndLocation = StringInStr($ClipData[$SearchLineNumber], "jpg"" alt=")
    If $ImageURLEndLocation <> 0 Then
     $ImageURLStartLocation = StringInStr($ClipData[$SearchLineNumber], "<img src=")
     $lineLength = StringLen ($ClipData[$SearchLineNumber])
     $ImageURLList[$CountURL] = StringTrimRight($ClipData[$SearchLineNumber], $lineLength-$ImageURLEndLocation-2)
     $ImageURLList[$CountURL] = StringTrimLeft($ImageURLList[$CountURL], $ImageURLStartLocation+9)
     ;downloadingThumbs
     InetGet($ImageURLList[$CountURL], $ImagePath & "thumb" & StringFormat("%02d", $CountURL+1) & ".jpg",1,0)
     $ImageURLList[$CountURL] = "file:///" & $ImagePath & "thumb" & StringFormat("%02d", $CountURL+1) & ".jpg"
     $ImageURLList[$CountURL] = StringReplace($ImageURLList[$CountURL], "\", "/")
     $CountURL = $CountURL+1
     ReDim $ImageURLList[$CountURL+1]
     ExitLoop
    EndIf
   Next
  Next

The line it "complaints about is

$LessonImageURLEndLocation = StringInStr($ClipData[$SearchLineNumber], "jpg"" alt=")

What this section of the code is trying to get is get an HTTP path to an image from a webpage. The webpage source code is in a declared array variable named $ClipData and each array value consist one line of the HTML code.

$ArrayInfoLocation is a list of line number (which equal to array enteries) where it should start do the search in the $ClipData array.

There aren't any specific keywords indications of where the image paths are; the only thing I know is that it's about 1-6 lines above the "start" line I have in the $ArrayInfoLocation.

I have some other instances VERY similar to this to extract other fields but the only different there is the second FOR loop, which doesn't "go reversed" (I even tried not going reversed and had the same error).

Am I missing/overlooking something?

Looking at what I wrote I hope someone can understand and help and I'm sorry of my "bad coding" - after all I'm not a programmer, just a hobbiest ;)

Thanks for your time and I'm happy to know of AutoIt, it's definitly going to be useful :)

Link to comment
Share on other sites

Hello 0Ethan0,

First, Welcome to the AutoIt Forums!

Second, Don't apologize for lengthy posts, It's better to give all the tools in order to help than to just ask "Whats wrong with my script", However, the line of code your having problems with is not included in your reproducer script. The section of script with that line is where the problems is. Your reproducer script finishes it's loop because it has apparently performed as coded. It's the line that is having a problem determining your need.

Generally 'Array Variable subscript badly formatted' is from when you are trying to call outside of the bounds of the array. Try debugging your code a little further, and you may find the answer yourself. When I hit unexpected errors, I generally add a function to write to the console reproducing/showing the code/variables before the line it breaks in. If you use scite to code and run your scripts, the Function ConsoleWrite() will output to Scite's Output pane.

This small example will show if your variable $SearchLineNumber exceeds the boundary of your array $ClipData.

ConsoleWrite( '- Does $SearchLineNumber(' & $SearchLineNumber & ') exceed  UBound($ClipData)=('& UBound($ClipData) & ')' & @LF )
$LessonImageURLEndLocation = StringInStr($ClipData[$SearchLineNumber], "jpg"" alt=")

If the variable $SearchLineNumber is within the boundaries of your array $ClipData, then the next thing I would do is look at the source it is gathering this information from, and determine if the data it is collecting is corrupted or formatted differently then your reproducer script is expecting.

Good Luck and Happy Coding!

Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry. 

Link to comment
Share on other sites

Shazam!

Wow! fastest respond I ever got in a forum :D

THANK YOU Realm, you're the :)!

I am used to generate a "Test Message Box" with the variables but I thinkg I tested all the variables except this one... ;)

With your extra line I managed to find the problem and fixed it (it's amazing that all it take is one line of code between success and a failure :D ).

Apparently the last value of the array had a 0 (or "reserved") and by doing stepping "-1" it got an error - obviously.

The way arrays are treated in AutoIt are similar to what I know but declaring them is a bit different. I'll pay more attention to it from now on.

Thanks again for the quick help and as "someone" said "Good Luck and Happy Coding!"

:

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...