Jump to content

Need help in Loops


Recommended Posts

Hi all,

i writed the followed code to do some things automaticaly. The clicks works very well but i have a feeling that the loop im using will never reach the wated value.

Is there any way for a newbie coder as me to check the loops from autoit?

Thanks in advance

sleep(5000)

MouseClick("right", 1370, 973)

Sleep(1000)

MouseClick("left", 1417, 980)

sleep(3000)

MouseClick("left", 1464, 169)

sleep(500)

MouseClick("left", 1484, 73)

sleep(2000)

Do

$i = 0

MouseClickDrag("left", 1306, 971, 1299, 795)

sleep(245900)

$i = $i + 1

if $i = 14 Then

MouseClickDrag("left", 1227, 791, 1370, 973)

sleep(1000)

MouseClick("right", 1370, 975)

sleep(2000)

MouseClick("left", 1417, 980)

sleep(3000)

MouseClick("left", 1464, 169)

sleep(3000)

MouseClick("left", 1484, 73)

$i = 0

EndIf

Until $i = 1000

Link to comment
Share on other sites

Hi all,

i writed the followed code to do some things automaticaly. The clicks works very well but i have a feeling that the loop im using will never reach the wated value.

Is there any way for a newbie coder as me to check the loops from autoit?

Thanks in advance

sleep(5000)

MouseClick("right", 1370, 973)

Sleep(1000)

MouseClick("left", 1417, 980)

sleep(3000)

MouseClick("left", 1464, 169)

sleep(500)

MouseClick("left", 1484, 73)

sleep(2000)

Do

$i = 0

MouseClickDrag("left", 1306, 971, 1299, 795)

sleep(245900)

$i = $i + 1

if $i = 14 Then

MouseClickDrag("left", 1227, 791, 1370, 973)

sleep(1000)

MouseClick("right", 1370, 975)

sleep(2000)

MouseClick("left", 1417, 980)

sleep(3000)

MouseClick("left", 1464, 169)

sleep(3000)

MouseClick("left", 1484, 73)

$i = 0

EndIf

Until $i = 1000

Welcome to the AutoIt forms 'niewbie :P

(Hopefully your name won't be appropriate for long.)

If you want to loop a certain number of times it might be easier to use a for/next loop instead of do while.

As it is the value of $i is set to 0 every time the loop starts so it never gets to 14. If you removed that line then it will always get to 14, but when it does it will be reset to 0 again, so it will never get passed 14. Even if you stopped resetting the value of $i to 0 it would still take a very long time to reach 1000, well about 3 days I guess.

Since I don't know what you're trying to do I can't offer a good solution.

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.
Link to comment
Share on other sites

Welcome to the AutoIt forms 'niewbie :P

(Hopefully your name won't be appropriate for long.)

If you want to loop a certain number of times it might be easier to use a for/next loop instead of do while.

As it is the value of $i is set to 0 every time the loop starts so it never gets to 14. If you removed that line then it will always get to 14, but when it does it will be reset to 0 again, so it will never get passed 14. Even if you stopped resetting the value of $i to 0 it would still take a very long time to reach 1000, well about 3 days I guess.

Since I don't know what you're trying to do I can't offer a good solution.

What im loooking to do is to run the whole procedure, till i stop it (close the script). For that reason h set the i=1000.

The problem that i started to see, is that the $i never reach the 14. Ill do some testing with for/next as your advice, and posting back :P

Link to comment
Share on other sites

Ok. what i did.

MouseClick("left", 1464, 169)

Sleep(1000)

MouseClick("left", 1484, 73)

Sleep(1000)

$c = 1 ; im using this to control the whole loop to run "forever"

For $i = 1 to 14 Step 1 ; according to the help file the $i starts counting from one till it reach the 14

MouseClickDrag("left", 1306, 971, 1299, 795) ; no comments on this :P

Sleep(245900)

Next ; when the $i gets the 14 value, will execute the following commands.

MouseClick("left", 1464, 169)

Sleep(1000)

MouseClick("left", 1484, 73)

$c = $c +1

Until $c = 1000

; i hope im right :P)

Link to comment
Share on other sites

In my newbie coding situation i had some problems in "while-wend" and for that reason i returned to the previous state of coding.

I wanted to be able to start the whole program by pressing one button.

For that reason i stole hotkeyset function from help file :P . there what i did

During some experiments i tried to "restart" the whole script when a specific key was pressed (lets say insert) but i was unable. Can anyone give me an advice on this?

Thanks much again.

; Hot Keys

Global $Paused

HotKeySet("{PAUSE}", "TogglePause")

Send("{PAUSE}") ; it starts paused

MouseClick("left", 1464, 169)

Sleep(1000)

MouseClick("left", 1484, 73)

Sleep(1000)

Do

$c = 1 ; im using this to control the whole loop to run "forever"

For $i = 1 to 14 Step 1 ; according to the help file the $i starts counting from one till it reach the 14

MouseClickDrag("left", 1306, 971, 1299, 795) ; no comments on this

Sleep(5000)

Next ; when the $i gets the 14 value, will execute the following commands.

MouseClick("left", 1464, 169)

Sleep(1000)

MouseClick("left", 1484, 73)

$c = $c +1

Until $c = 1000

Func TogglePause()

$Paused = NOT $Paused

While $Paused

sleep(1000)

ToolTip('"Pause"',0,0)

WEnd

ToolTip("")

EndFunc

Edited by niewbie
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...