Sign in to follow this  
Followers 0
Leoshin

Creating a Loop with increasing Values

9 posts in this topic

Hello Communtiy:

I am working on an application that is able to sort sheets from different rows and columns. ( See code below )

The code below is the first instance of a 3 segmented sorting function ( all basically identical )

What i am looking for now is this:

Is it possible to make this application run in 30 loops and after each loop have the mouse value for "sheet" be replaced by a next higher value ?

The values for the horizontal would be 1134 , 1165 ,1195, 1235,1270 and 1315 whereas Vertikal is 95 ,132 ,170 etc . Once the value 1315 is reached for a sheet in a loop it should go back to 1134 and increase the value of the vertikal coordinate.

I am pretty sure it is possible, it just exceeds my expertise.

Thank you very much in advance !

HotKeySet("{ESC}","Quit")

MsgBox(0, "Select", "Please select your Sheets")

Sleep(10000)

MouseMove(668, 335, 0)

MouseClick("left")

MouseClick("left")

Sleep (1000)

MouseMove (92, 325)

MouseClick("left")

MouseMove (457, 289)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseClick("right")

Sleep (500)

MouseMove (762, 343)

MouseClick("left")

Sleep (1000)

MouseMove (524, 173)

MouseClick("left")

Sleep (1000)

MouseMove(668, 335)

MouseClick("left")

Sleep (1000)

MouseMove(99, 251)

MouseClick("left")

Sleep (1000)

MouseMove(1130, 170)

MouseClick("right") ; Sheet 1 / 3

Sleep (1000)

MouseMove(1132, 93)

MouseClick("right") ; Sheet 1 / 1

Sleep (1000)

MouseMove(1123, 354) ; Sheet 1 / 8

MouseClick("right")

Sleep (1000)

MouseMove(107, 133)

MouseClick("left") ;

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1165, 97)

MouseClick ("right")

Sleep (1000) ; Sheet 2 / 1

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1195, 99)

MouseClick("right")

Sleep (1000) ; Sheet 3 / 1

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ;Sheet 1 / 1

MouseMove(1235, 99)

MouseClick("right")

Sleep (1000) ; Sheet 4 / 1

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1270, 99)

MouseClick("right")

Sleep (1000) ; Sheet 5 / 1

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1315, 99)

MouseClick("right")

Sleep (1000) ; Sheet 6 / 1

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1134, 95)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1134, 132)

MouseClick ("right")

Sleep (1000) ; Sheet 1 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1165, 132)

MouseClick("right")

Sleep (1000) ; Sheet 2 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ;Sheet 1 / 1

MouseMove(1195, 132)

MouseClick("right")

Sleep (1000) ; Sheet 3 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 95)

MouseClick("right")

Sleep (1000) ;Sheet 1 / 1

MouseMove(1235, 132)

MouseClick("right")

Sleep (1000) ;Sheet 4 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1270, 132)

MouseClick("right")

Sleep (1000) ;Sheet 5 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(1123, 93)

MouseClick("right")

Sleep (1000) ; Sheet 1 / 1

MouseMove(1315, 132)

MouseClick("right")

Sleep (1000) ;Sheet 6 / 2

MouseMove(107, 133)

MouseClick("left")

Sleep (4500)

MouseMove(263, 12)

MouseClick("left")

Sleep (1000) ;

Share this post


Link to post
Share on other sites



I am working on an application that is able to sort sheets from different rows and columns.

You are talking about Excel sheets, right?

If yes, did you have a look at the Excel UDF built into AutoIt?

The sort function only allows to sort on one column but on the forum you'll find functions which do more.


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

You are talking about Excel sheets, right?

If yes, did you have a look at the Excel UDF built into AutoIt?

The sort function only allows to sort on one column but on the forum you'll find functions which do more.

No its not about Excel , i know my stuff with excel ^^

External Application , thats why i created a start to allow me to pick it.

Basically i am just seeking a 30 times loop command whereas the values of the "Sheet" positions are always upgraded to the next bigger value.

Share this post


Link to post
Share on other sites

$iHorizontal = 1134

For $i = 0 To 30
   $iHorizontal += 30
   If $iHorizontal = 1315 Then ExitLoop
Next

something like this?

Share this post


Link to post
Share on other sites

$iHorizontal = 1134

For $i = 0 To 30
$iHorizontal += 30
If $iHorizontal = 1315 Then ExitLoop
Next

something like this?

Hello , thats an interesting command and a start :guitar:

But i am seeking to wrap the whole body in a loop. In Pseudo Code would be something like this:

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

Start application

if "Loop" =30 goto "Exit"

Loop=0

MouseMove(A1130, B170)

MouseClick("right") ; Sheet 1 / 3

if A:=1130 set A:=1165

If A:=1165 set A:=1195

etc.

If A:>1315 Set B:=+30 and Set A:=1135

Add Loop +1

Goto "Loop"

Exit

IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

your example doesnt make any sense.

but something like this?

$A = 1130
$B = 170

For $i = 0 To 30 ; will run loop 30 times
   MouseMove(A & $A, B & $B)
   MouseClick("right")  ; Sheet 1 / 3
   
   If $A = 1130 Then $A = 1165
   If $A = 1165 Then $A = 1195
   If $A > 1315 Then $B += 30 And $A = 1135
Next
Edited by kor

Share this post


Link to post
Share on other sites

Okay there's several things you need to know. Firstly a For loop increments a value by another value. The default increment is 1.

For $i = 0 To 2 ; the loop stops when the variable $i = 3
    MsgBox(0, "Variable $i", $i) ; The variable $i is increased automatically.
Next

Next your use of conditional statements is not AutoIt. The conditional statement:

If A:>1315 Set B:=+30 and Set A:=1135

Should be written like this:

; Always declare variables before you use them
Dim $var1 ; Declare variable A
Dim $var2 ; Declare variable B

; Assign a numeric value to the variables
$var1 = 1316
$var2 = 0

If $var1 > 1315 Then ; Pseudo code => If A:>1315
    $var2 += 30 ; Pseudo code => Set B:=+30 and
    $var1 = 1135 ; Pseudo code => Set A:=1135
EndIf

MsgBox(0, "Value", "$var2 = " & $var2) ; Should be 30

Now you can put your conditional statements inside your loop like this.

Dim $var1 = 1316
Dim $var2 = 0

For $i = 0 To 2
    If $var1 > 1315 Then
        $var2 += 30
        $var1 = 1135
    EndIf
Next

MsgBox(0, "Value", "$var2 = " & $var2) ; Should be 30

You should make sure understand this code and read up on the functions from the help file. You need to focus on the functions and Keywords... If, Else, ElseIf, For To & Next.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

your example doesnt make any sense.

but something like this?

$A = 1130
$B = 170

For $i = 0 To 30 ; will run loop 30 times
MouseMove(A & $A, B & $B)
MouseClick("right") ; Sheet 1 / 3

If $A = 1130 Then $A = 1165
If $A = 1165 Then $A = 1195
If $A > 1315 Then $B += 30 And $A = 1135
Next

This looks very good ( and thank you for the comments, my expertise with AutoIt after 2 days is rather limited )

I will try it out and let you know tomorrow.

Thank you very much already!

EDIT: Also thank you very much at czardas for the starting point, i will start digging in tomorrow

Edited by Leoshin

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Hello Community , okay i am a lot further now but its still not working as it should.

I made a schematic what sorting function i am trying to acclomplish.

Did i mess up the syntax somewhere ?

Posted Image

otKeySet("{ESC}","Quit")
MsgBox(0, "Select", "Please open your Sheet ")
Sleep(10000)

Dim $A ; Declare variable A-F
Dim $B
Dim $C
Dim $D
Dim $E
Dim $F


$A = 1135 ; Assign a numeric value to the variables
$B = 165 ;
$C = 1135
$D = 95
$E = 1165
$F = 95

For $i = 0 to 30 ; Big loop to initiate first sorting Step

MouseMove($A , $B) ;Click Row 1 Column 3 on the sheet
MouseClick("right")
Sleep (1000)



While $A < 1346 ; Should increase "A" by 35 with every loop ( one row to the right per run and one column down if it reaches the sixt row )
$A=$A+35
WEnd

If $A = 1345 Then ; When "A" reaches 1345 (Row 6) it should become 1135 again (Row 1) and the mouse cursor should shift a column deeper
$B += 35
$A = 1135
EndIf





For $i = 0 To 3 ; Loop in the Loop sets positions for the sorting process

$C=$A ; Puts "Click 2" in the same row as "Click 1"
$D=$B-70 ; "Click 2" should be always 2 columns higher than "Click 1"
$E=$C+35 ; Puts Click 3 one row ahead of CLick 2

MouseMove($C , $D)
MouseClick("right")
Sleep (1000)

MouseMove(107, 133) ; Goes to "Click 3"
MouseClick("left")
Sleep (4500)

For $i = 0 To 12 ; Loop in the Loop in the Loop does the sorting

MouseMove($C , $D)
MouseClick("right")
Sleep (1000)

MouseMove($E , $F)
MouseClick("right")
Sleep (1000)

MouseMove(107, 133) ; Goes to "Click 3"
MouseClick("left")
Sleep (4500)

While $E < 1346 ; Should increase "E" by 35 with every loop
$A=$A+35
WEnd


If $E = 1345 Then ; When "E" reaches 1345 it should become 1135 again and "F" is increased by 35
$F += 35
$E = 1135
EndIf
Next



Next

Next

Edit: Sorry for the messy look of the code, i had pasted it properly formatted :(

Edited by Leoshin

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