Loop increment value

Recommended Posts

```For \$A1 = 12 To 11 + \$Total

For \$B1 = 1 To (\$oExcel.Application.Cells(\$A1,6).Value)   ; This value is from the Excel file. It can be from 1 - 9.

For \$N1 = 7 To ???  ; This is based on the value of \$B1 ((1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)

Send("-"& (\$oExcel.Application.Cells(\$A1,\$N1).Value) &"/"& (\$oExcel.Application.Cells(\$A1,\$N1+1).Value))
Sleep(400)
Send("{ENTER}")
Sleep(700)
Next
Next
Next```

I am not able to figure how to loop \$N1 as follows

If the Value of \$B1 = 1 then \$N1 = 7

If the Value of \$B1 = 2 then \$N1 = 17

If the Value of \$B1 = 3 then \$N1 = 27

If the Value of \$B1 = 4 then \$N1 = 37

The value of \$N1 comes from \$B1 where 1 = 7, 2 = 17, 3 = 27, 4 = 37, 5 = 47)

Thank You

Share on other sites

I think you want to drop the third loop and use this instead:

`\$N1 = \$B1 * 10 - 3`

But I'd highly suggest looking into setting the formula/value of the cell instead of using Send. It's super effective

All my code provided is Public Domain... but it may not work.  Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Share on other sites
```\$step = 10
For \$N1 = 7 To (10 X (\$oExcel.Application.Cells(\$A1,2).Value)) Step \$step```

How to indicate the loop 'To' value as 10 x value extracted from a specific excel cell, and start from 7 and then increase the loop in multiples - 7, (10X2) = 20, (10X3) = 30, (10X4) = 40. But because we start from 7 and step up by 10, the loop counter would go 7, 17, 27, 37.....

Share on other sites

Hi, can you explain what you want to do ?

When you say:

Quote

But because we start from 7 and step up by 10, the loop counter would go 7, 17, 27, 37.....

Do you mean/want  that the loop counter should go in 7, 17, 27

or do you want that the loop counter should go 7, 10, 20, 30, 40, 50 ?

Share on other sites
```\$iCount = (\$oExcel.Application.Cells(\$A1,6).Value)
\$step = 10
For \$N1 = 7 To 10 * \$iCount Step \$step
Send("-"& (\$oExcel.Application.Cells(\$A1,\$N1).Value) &"/"& (\$oExcel.Application.Cells(\$A1,\$N1+1).Value))
Sleep(400)
Send("{ENTER}")
Sleep(700)
Send("{ESC}")
Sleep(300)

Send (\$oExcel.Application.Cells(\$A1,\$N1+7).Value)
Sleep(400)
Send("{ENTER}")
Sleep(700)
Send("{ESC}")
Sleep(300)```

I think we got it to work.

1- So I wanted the script to read the data from cell (\$A1,6) to know how many times to loop.

2- If  the value in cell (\$A1,6) is 5, then the script will loop from 7 to 50 (10 X 5)

3- Because of the \$Step, it will jump 10 numbers. That means it will go 7, 17 (7+10), 27 (17+10), 37 (27+10), 47 (37+10)

4- The loop will stop at 47 since 50 is the end of loop and next loop counter value will go over 50

5- \$N1 starts from value 7 which make the script read cell value starting (\$A1,7)

Thank you for your help

We did it 🙂

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

• Similar Content

• By mmoalem
Hi all - I have created a simple script that turn on cctv software (contacam)  when my phone does not ping back (when I'm out of range of home network)
#include <MsgBoxConstants.au3> \$iPing = 0 For \$i = 5 To 1 Step -1 ; this 5 loops cycle is just for testing - please ignnore - when complete it will be an endless loop Example() Sleep(120000) Next Func Example() ; Ping the phone. \$iPing = Ping("192.168.1.102") If \$iPing Then ; If a value greater than 0 was returned then turn off camera. _endCCTV() Else _startCCTV() ; If a value of 0 was returned then turn on camera. EndIf EndFunc ;==>Example Func _startCCTV() ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "on") Sleep(10000) ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "50") EndFunc Func _endCCTV() ShellExecute("C:\contacam capture\FJ Camera\CAMERA_REC_SENSITIVITY.bat", "0") Sleep(10000) ShellExecute("C:\contacam capture\FJ Camera\CAMERA.bat", "off") EndFunc

the problem I have is that in this format the script run the bat file that turn on the camera (or off) everytime the ping runs but obviously once the ping returns 0 and the camera starts I only want to run the bat on ping NOT 0 (turn off camera)

• include-once #include <File.au3> #include <Excel.au3> #include <String.au3> #include <MsgBoxConstants.au3> Local \$file = "TEST.log" FileOpen(\$file, 0) \$TTLPax = 1 For \$i = _FileCountLines(\$file) - \$TTLPax to _FileCountLines(\$file) \$line = FileReadLine(\$file, \$i) Global \$TktNo = StringMid(\$line, 8, 13) ; reads 13 characters from \$Line starting from the 8th character msgbox(0,'',\$TktNo) ; This is just for me to debug For \$NoOfPax = 1 to 2 local \$TTLSeg = 2 msgbox(0,'',\$TTLSeg) msgbox(0,'',"7ABC"& \$TktNo &"'N"& \$NoOfPax &".1'C1,2'S1,2'B") ; This makes 7ABC1234567890123'N1.1'C1,2'S1,2'B ;But in the next loop I want the value to be 7ABC1234567890333'N2.1'C1,2'S1,2'B Next ExitLoop Next *TEST
JAMES BAKER
1.NYC-23JAN
2.TJ 1234567890123
3.TJ 1234567890333
I am reading a file with last 5 lines as above. I want to be able to loop through and pick the values as follows
1- Pick 1234567890123
2- Use it to build a format with N1.1
3- Pick 1234567890333
2- Use it to build a format with N2.1
Need help with the loop. Thank You

• By ssah8
So im creating a bot that logs in on a website. The website got a dropdown menu, and I have to choose the right one to login (Student)
#include <IE.au3>
#inculude <Inet.au3>
\$oIE = _IECreate("<snip>")
\$Name = _IEGetObjByName(\$oIE, "ssusername")
\$Pass = _IEGetObjByName(\$oIE, "sspassword")
\$dropdown = _IEGetObjByName(\$oIE, "usertype")
_IEPropertySet(\$Name, 'innerText', 'censored')
_IEPropertySet(\$Pass, 'innerText', 'censored')
_IEPropertySet(\$dropdown, 'innerText', 'Student') <------ How do I make the dropdown list select "Student"?

• By ThePoro
Hi everyone.
I want it runs from 1 to 100 and It opens 10 firefox profiles then access youtube. After I close a firefox window, the loop runs and wait for another window close until loop ends
I have a loop like this.
Func launch() Local \$from = Int(GUICtrlRead(\$input1)) Local \$to = Int(GUICtrlRead(\$input2)) If \$to <> "" Then While \$from <= \$to Local \$profile = \$to _RunDos("start firefox.exe -p " & \$profile & " -no-remote youtube.com") \$to=\$to+1 WEnd Else Local \$profile = \$to _RunDos("start firefox.exe -p " & \$profile & " -no-remote youtube.com") EndIf EndFunc Is there any solution?
Thank you!
• By Rhidlor
First off, the project I'm working on revolves around AS/400 "Client Access software", it's foundation is directly influenced by the thread linked at the bottom of this post. Moving on, to explain the problem I'm facing; my project utilizes an infinite While loop and automatically performs semi-hard coded monotonous tasks to save users time and effort, the problem is, occasionally and unexpectedly "Display Messages" will popup and the core script will continue executing instead of dismissing said message and the script "breaks". As a countermeasure I've added some code to the While loop in an effort to intervene and dismiss these display messages before the core script has a chance to do anything... however it doesn't work. I hope I didn't do too bad of a job explaining that.
So I think my question is: How can I temporarily "pause" the core script when these messages spontaneously appear?
The only other solution I thought of would be to check if a display message has appeared before executing every line of code but that obviously isn't very practical.
Any and all help is greatly appreciated!
Thanks

;Loop to keep script running and handle display messages While 1 dismiss_display_messages() Sleep(50) WEnd ;Function to dismiss display messages Func dismiss_display_messages() If \$ps.SearchText("Display Messages") Then \$ps.SendKeys("[enter]", 8, 1) ;This while loop waits until the display message has disappeared to resume the core script While \$ps.SearchText("Display Messages") Sleep(100) WEnd EndIf EndFunc

×

• Wiki
• AutoIt Resources

• FAQ
×
• Create New...