Sign in to follow this  
Followers 0
GNGNUT

can you speed up loops?

10 posts in this topic

#1 ·  Posted (edited)

hi guys

new to all this and still getting my head around it

i have a simple script for work, when we need to create a button on our systems we get a lot of errors before we can choose the button we want to add

so i have created this

Func _WinWaitActivate($vWintitle, $vWinText, $timeout)

WinWait($vWintitle, $vWinText, $timeout)

If Not WinActive($vWintitle, $vWinText) Then WinActivate($vWintitle, $vWinText)

WinWaitActive($vWintitle, $vWinText, $timeout)

EndFunc ;==>_WinWaitActivate

for $i = 1 to 400

error()

Next

func error()

$vWintitle = "Error"

$vwintext = "OK"

$vbut = "[CLASS:Button; INSTANCE:1]"

_WinWaitActivate($vWintitle, $vWinText, 2)

Controlclick ($vWintitle,$vWinText,$vbut)

EndFunc

This error Has different count depending on the system (enviroment) we are using and currently set at 366 time

the loop runs too slow (1 sec per click) and wondering if i can speed this loop up "pending the error window box"

kind regards

craig

Edited by GNGNUT

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Do I understand you correctly that you have an application that throws an error window from time to time and if the error window appears you want your script to click on the button?

If yes, we have something similar created for the OutlookEX UDF to click away the Outlook security warning. _OL_Warnings is started by the main script. It waits until the error window appears and clicks the OK button. The _OLWarnings script is terminated when the calling process has finished.

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

#4 ·  Posted (edited)

I would use:

error(400)
 
Func error($number)
    $vWintitle = "Error"
    $vWinText = "OK"
    $vbut = "[CLASS:Button; INSTANCE:1]"
    For $i = 1 To $number
     WinWait($vWintitle, $vWinText, 2)
     If Not WinActive($vWintitle, $vWinText) Then WinActivate($vWintitle, $vWinText)
     WinWaitActive($vWintitle, $vWinText, $timeout)
     ControlClick($vWintitle, $vWinText, $vbut)
   Next
EndFunc   ;==>error
Should be much faster because you eliminate 800 function calls. 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

#5 ·  Posted (edited)

thank you for you feed back guys :graduated::)

@water 1st message basicly i need this to function when i only goto add icon due to needing to read system errors that may only pop up here and there

i know there is a issue when adding icon, and this is the reason for the small script ;):) only problem is i dont have a lot to work with.

below is the summary from the info help tool

I could set it to use the visable text but there can be a lot of different errors

and that leading to 300 + different bits of script for ever one.

>>>> Window <<<<

Title: Error

Class: #32770

Position: 822, 491

Size: 281, 126

Style: 0x94C801C5

ExStyle: 0x00010101

Handle: 0x005203D0

>>>> Control <<<<

Class:

Instance:

ClassnameNN:

Name:

Advanced (Class):

ID:

Text:

Position:

Size:

ControlClick Coords:

Style:

ExStyle:

Handle:

>>>> Mouse <<<<

Position: 970, 506

Cursor ID: 2

Color: 0x0055EA

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

OK

Unable to set com-handle property. (5677)

>>>> Hidden Text <<<<

@ water. 2nd message. this script seems to run at the same speed as the one I wrote :)

not sure if its the winwait part holding it up or the winactivate as it needs to do this each time.

@chrisl. this speeds it up but if there is a small dely in the screen coming up it will end the script.

have been playing with it

func error()

$vWintitle = "Error"

$vwintext = "OK"

$vbut = "[CLASS:Button; INSTANCE:1]"

winActive($vWintitle, $vWinText)

Controlclick($vWintitle,$vWinText,$vbut)

EndFunc

but this stops just like Chrisl idea

Edited by GNGNUT

Share this post


Link to post
Share on other sites

i have a simple script for work, when we need to create a button on our systems we get a lot of errors before we can choose the button we want to add

I have re-read your first post. I fear I still don't get the point. Some questions to make it clearer:
  • How do you create the button?
  • On what systems do you create the button?
  • What kind of errors do you get?
  • Who raises the error (your application, an Autoit script ...)?

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

#7 ·  Posted (edited)

im using visula files and it is visual files that is kicking up the error.

to creat a button / icon simple right click in the taskbar inside of visual files and select create icon < at this point is when the errors start,

"Unable to set com-handle property. (5677)"

"Error occurred while accessing component property/method: Add.

Element not found

Error code: 0x80020009 ADD-LISTVIEW-ITEM ficonadn.w (5890)"

"Error occurred while accessing component property/method: Listitems.

Element not found

Error code: 0x80020009 ADD-COLUMN-ENTRY ficonadn.w (5890)"

heres 3 errors taht pop up within the 366 i have at the moment :graduated:

Edited by GNGNUT

Share this post


Link to post
Share on other sites

thank you for you feed back guys :graduated::)

@ water. 2nd message. this script seems to run at the same speed as the one I wrote ;)

not sure if its the winwait part holding it up or the winactivate as it needs to do this each time.

@chrisl. this speeds it up but if there is a small dely in the screen coming up it will end the script.

have been playing with it

func error()

$vWintitle = "Error"

$vwintext = "OK"

$vbut = "[CLASS:Button; INSTANCE:1]"

winActive($vWintitle, $vWinText)

Controlclick($vWintitle,$vWinText,$vbut)

EndFunc

but this stops just like Chrisl idea

Do what Water suggested and still put Opt("WinWaitDelay",1) at the top of the script as by default Autoit waits 250ms after every window action

You might also want to concider using ControlFocus before ControlClick which can help if you still get things stoppping.

ControlFocus($vWintitle,$vWinText,$vbut)

Controlclick($vWintitle,$vWinText,$vbut)

What happens after you click the button, does the window disappear?

Share this post


Link to post
Share on other sites

yes soon as i click ok to error message the next one pops up and so on :graduated:

that has made the loop go a lot faster thanks guys for all your help ;):)

script as iit stands :):)

Opt("WinWaitDelay",2)

error(400)

Func error($number)

$vWintitle = "Error"

$vWinText = "OK"

$vbut = "[CLASS:Button; INSTANCE:1]"

For $i = 1 To $number

WinWait($vWintitle, $vWinText, 2)

If Not WinActive($vWintitle, $vWinText) Then WinActivate($vWintitle, $vWinText)

WinWaitActive($vWintitle, $vWinText, $timeout)

ControlClick($vWintitle, $vWinText, $vbut)

Controlfocus($vWintitle,$vWinText,$vbut)

Next

EndFunc ;==>error

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