Help: List index out of bounds (-1)

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Help: List index out of bounds (-1)

Post by Liberty » Wed Aug 22, 2007 10:34 am

I have made a rather simple login script
which I want to run by the its .exe file.

However there seems to be a conflict when Macro Scheduler is runnning as I often get the above error message.

I have tried to make many changes in the macro to avoid this.

Observations:
As this error does not occur for other macros I think that the use of
Press Down
in the macro to scroll down and reach the input control causes the error in this case.

If Macro Scheduler is hidden or closed this error seems to not appear.

1. What does cause this conflict?
2. What does this error really mean?
3. How do I avoid this bug/error when I want to use this macro and Macro Scheduler at the same time? Also with scheduled macros.


Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 22, 2007 10:42 am

Help us help you. Show us your script. Which version are you running?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Wed Aug 22, 2007 11:10 am

_____________________________________________________________
Remark>Login to Nordnet
Let>YES=1
Let>NO=0

Let>address1=https://www.nordnet.se/mux/login/startSE.html
Let>address2=https://www.nordnet.se/mux/web/depa/minsida.html
Let>address3=https://www.nordnet.se/mux/login/startSE.html#

/*May be a solution
Remark>Hide MacroScheduler
IfWindowOpen>Macro Scheduler*
SetFocus>Macro Scheduler*
Press CTRL
Press F4
Release CTRL
EndIf
*/

IfWindowOpen>di.se - Windows Internet Explorer
CloseWindow>di.se - Windows Internet Explorer
WaitWindowClosed>di.se - Windows Internet Explorer
EndIf
Let>NoWindow=NO
Let>k=1
Repeat>NoWindow
Let>k=k+1
IfWindowOpen>Nordnet*
CloseWindow>Nordnet*
Let>WW_TIMEOUT=10
WaitWindowClosed>Nordnet*
If>k>10
Let>NoWindow=YES
EndIf
Else
Let>NoWindow=YES
EndIf
Until>NoWindow=YES

CapsOff
Remark> Use the IEAuto here
LibLoad>IEAuto.dll,hIE
If>hIE=0
MessageModal>Could not load IEAuto.dll, make sure it is in the path or edit the LibLoad line.
Goto>Endscript
EndIf

Remark>Open the nordnet page
LibFunc>hIE,CreateIE,IE,0
LibFunc>hIE,Navigate,r,%IE%,%address1%
LibFunc>hIE,WaitIE,r,%IE%
Wait>1
WaitWindowOpen>Nordnet - Välkommen - Windows Internet Explorer
WindowAction>1,Nordnet - Välkommen - Windows Internet Explorer

Remark>Give login data
Wait>0.5
SetFocus>Nordnet - Välkommen - Windows Internet Explorer
MouseMove>150,150
LClick
Remark>We use image recognition to find the first input field
Remark>First we have to scroll down
WaitReady>0
Press DOWN
Press DOWN
GetScreenRes>X,Y
ScreenCapture>0,0,X,Y,D:\MacroData\Sites\screen.bmp
FindImagePos>D:\MacroData\Sites\inputfield.bmp,D:\MacroData\Sites\screen.bmp,0,1,X,Y,NumFound
If>NumFound>0
MouseMove>X_0,Y_0
Else
MessageModal>Error: No input field found, %SCREENCAP_RESULT%
Goto>EndScript
EndIf

LClick

SetFocus>Nordnet - Välkommen - Windows Internet Explorer
WaitReady>0
Send>11111
Wait>0.1
WaitReady>0
Press TAB
Send>xxxxx
Wait>0.1
WaitReady>0
Press TAB
Send>yyyyyyy
Wait>0.2

Remark>Move to the login button and click it
SetFocus>Nordnet - Välkommen - Windows Internet Explorer
Remark>Use IEAuto in Webrecorder and index which is found to be 4 in this case
Let>FrameName={""}
Let>FormName={""}
Let>TagValue={"4"}
LibFunc>hIE,ClickTag,r,%IE%,str:FrameName,str:FormName,A,INDEX,str:TagValue
Wait>1

WaitWindowOpen>Nordnet - Startsida - Windows Internet Explorer
Label>EndScript
Exit

**********************************************************************

SRT>MinimizeAllWindows
Press LWinkey
Send>d
Release LWinkey
END>MinimizeAllWindows

SRT>MaximizeAllWindows
Press LWinkey
Press Shift
Send>m
Release Shift
Release LWinkey
END>MaximizeAllWindows
_______________________________________________________


One test variant of the code is above.
You could ignore the closing of windows at the beginning
I think that you will get the error if you have the MS open and run this as an exe at the same time - but I am not quite sure.

I use version 9.0

If you have any other comments to my code, I would appreciate.
I am an experienced programmer but new to MS.

This macro worked well before I had to add the Press Down after home page changes.

Thanks





[/code]

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 22, 2007 11:30 am

Can you clarify something for me - when the Press Down is issued which window has the focus? Are you sure that the correct window is focused? I am wondering if the problem might be that Macro Scheduler still has the focus at this point and want to eliminate that possibility. The reason I ask is that you say the error only occurs when Macro Scheduler is visible. So leading me to wonder if it still has the focus when you send the keystroke.

Are you also positive that the Press Down command is the culprit? Do you have log files or have you debugged in order to prove this?
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Wed Aug 22, 2007 12:10 pm

As you see I use the SetFocus command, which should set the focus to the correct window. Does not the SetFocus command work when the MS is open?

However the error message seems to come from Macro Scheduler.

I am not quite sure if the Press Down is the culprit but think so.

My conclusions are not firm at this point, therefore I have posted this message.

Also it is not quite certain that the error only appears when MS is visible.

I have not fully tested the variant where I hide MS.
I could send you the image file for testing if you send me your email address.

The log files have so far given me nothing. They show that the macro has been running to the end (START/END for each line of code). How should I use them?

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Aug 22, 2007 1:11 pm

Yes, of course SetFocus works when Macro Scheduler is open. I just wanted to get your clarification that you are focusing a window and that the window IS being focused correctly.

As you are not entirely sure which command is the culprit please enable logging for the macro. Then next time you get the error message, BEFORE clearing the error message, grab a copy of the log file from disk and look at the last entry.

Which version of Macro Scheduler are you using? I need the full version number. Look under Help/About.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Wed Aug 22, 2007 2:18 pm

I will check the log file as you say and come back.

The full version no is 9.0.052.

Could you pls tell me your experience of this error message and what it stands for?

When I do not get this error the macro is working quite well. Before this change (Press Down) due to a home page update recently, the macro was working without any problem for about a month.

Thanks

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Wed Aug 22, 2007 9:41 pm

I was wrong.

When this error occurs the logfile stops at
CloseWindow>Nordnet*.

The error message is shown on the MS window and there is a sound

It seems that MS in this case is not able to close the window, even if there is a window of this kind open.

I cannot determine the circumstances when these error messages appear - (there is a loop over k - why I now have changed some constants in it). Sometimes there is no error.

Thanks for a reply

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Aug 22, 2007 10:31 pm

Looking up the error "List index out of bounds (-1)" in Google groups, it seems that it is a Delphi error that possibly occurs when a variable is not initialized. Based on this probably useless information and considering the script location where your logfile halts, I wonder why you are setting YES to 1 and NO to 0 in the opening lines of your code. The point of failure might indicate that there is a problem with the repeat statement that is using YES and NO for it's parameters. What happens if you eliminate the two lines?

//Let>YES=1
//Let>NO=0

Just a thought.

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Thu Aug 23, 2007 2:27 pm

I will test your proposal even if I do not believe in it.
I will tell you if this gives something.
The error that comes irregularly is quite disturbing.

I am grateful for all help

I generally use YES or NO in my code because I am used to it and it creates some clarity. I have it in several macros without this error.

My conclusion is that the error comes with the closewindow statement even if there is a window to close and that is given by the MS not my macro. I will now also test removing the loop but think that this will not help as the error comes for each k.

The error message has obviously been up for discussion in this forum several times before. You may search for it here. I did not find any useful hints but thought that someone from mjtnet could help.

Thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Aug 23, 2007 2:35 pm

Some apps will ignore a request from the CloseWindow command. Not sure if the problem is related. But please try this code instead:

SetFocus>Nordnet*
Press ALT
Press F4
Release ALT
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Thu Aug 23, 2007 4:42 pm

The closewindow loop works fine in another macro (with YES/NO) and also without the restriction through the variable k, which I put in to avoid an infinite loop here.

Your F4-proposal is adequate. I will test it. Also WF_TYPE=2.

Thanks

Liberty
Pro Scripter
Posts: 56
Joined: Wed Jun 06, 2007 11:56 am
Location: Sweden

Post by Liberty » Mon Aug 27, 2007 5:13 pm

I have used this script for some months without any problems.

However since the owner of this homepage changed it CloseWindow sometimes did not work and gave the described error message.
That is my conclusion, which Marcus Tettmar has said could be possible.

I have changed to use ALT F4 which has worked without errors for a few days now. The check of k has been removed.

However today the owner changed the homepage once more. I have not checked if CloseWindow may give an error again. I will keep F4 and report if something new will happen.

Thank you for your friendly support.

Maybe this case could initiate an improvement of the CloseWindow function in the future.

Post Reply
cron
Sign up to our newsletter for free automation tips, tricks & discounts