I'm having issues figuring out the correct syntax
I am looking to repeat a function until the row after the row I am working on is a different value. These values are coming from excel
Value 1: XLGetCell>xlH,Sheet1,row,2,field_2
Value 2: XLGetCell>xlH,Sheet1,check,2,field_22
I am having issues with the syntax of comparing field_2 to field_22
I have tried a few variations similar to:
Until>%field_2% != %field_22%
The error I get is:
Repeat> %field_2 ! Not Found!
I also want to add 1 to a count called "Lines" each time the function will repeat
if>%field_2%=%field_22%
Let>Lines=Lines+1
endif
Not sure if this is working either
[Solved] Repeat until not equal
Moderators: Dorian (MJT support), JRL
[Solved] Repeat until not equal
Last edited by cnfarber on Mon Aug 06, 2018 3:35 pm, edited 1 time in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: Repeat until not equal
Not equals should be <>, so:
Until>field_2<>field_22
Let>Lines=Lines+1 is correct. But make sure you initialise Lines, to e.g. 0 before the loop.
Until>field_2<>field_22
Let>Lines=Lines+1 is correct. But make sure you initialise Lines, to e.g. 0 before the loop.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Re: Repeat until not equal
I'm not getting an error message but it isn't repeating
Here is my entire test:
Let>filename=C:\Users\USER\Desktop\ExcelTest.xlsx
XLOpen>filename,1,xlH
setfocus>ExcelTest
let>row=1
let>check=2
repeat
Let>row=row+1
Let>check=check+1
XLGetCell>xlH,Sheet1,row,2,field_2
XLGetCell>xlH,Sheet1,check,2,field_22
send>%field_22%
press>tab
send>%field_2%
press>tab
wait>2
Until>%field_2<>field_22%
It will send the same value for both fields, which means it should repeat. After running through once, it stops.
I made sure that the the value it is using in excel is a number
Here is my entire test:
Let>filename=C:\Users\USER\Desktop\ExcelTest.xlsx
XLOpen>filename,1,xlH
setfocus>ExcelTest
let>row=1
let>check=2
repeat
Let>row=row+1
Let>check=check+1
XLGetCell>xlH,Sheet1,row,2,field_2
XLGetCell>xlH,Sheet1,check,2,field_22
send>%field_22%
press>tab
send>%field_2%
press>tab
wait>2
Until>%field_2<>field_22%
It will send the same value for both fields, which means it should repeat. After running through once, it stops.
I made sure that the the value it is using in excel is a number
- Grovkillen
- Automation Wizard
- Posts: 1131
- Joined: Fri Aug 10, 2012 2:38 pm
- Location: Bräcke, Sweden
- Contact:
Re: Repeat until not equal
Have you studied the manual? The repeat syntax is not even close to be correct.
Re: [Solved] Repeat until not equal
If anyone runs into something similar to this, here was my solution.
Added:
Let>stop=0
Repeat>row
if>field_2<>field_22
let>stop=row
end if
Until>row=stop
Special shout out to Grovkillen for being so helpful!
Added:
Let>stop=0
Repeat>row
if>field_2<>field_22
let>stop=row
end if
Until>row=stop
Special shout out to Grovkillen for being so helpful!
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Re: [Solved] Repeat until not equal
Could also have done:
Or you could remove the If and have the field2<>field22 comparison as part of the while condition:
But also I would probably have stored the last value in a variable rather than XLGetCell the next row each time. Only really need to get one row, and simply store the last value at the start of the loop. Your way you're reading the same row twice. No need.
Of course you could also just use a Label and Goto.
There's a tonne of ways to do it. It's just simple looping:
https://help.mjtnet.com/article/144-how ... p-the-loop
Code: Select all
Let>stop=0
While>stop=0
if>field_2<>field_22
let>stop=row
end if
EndWhile
Code: Select all
Let>field_2=1
Let>field_22=2
While>field_2<>field_22
//bla bla bla
EndWhile
Of course you could also just use a Label and Goto.
There's a tonne of ways to do it. It's just simple looping:
https://help.mjtnet.com/article/144-how ... p-the-loop
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?