i=i+1 does not increment
Moderators: JRL, Dorian (MJT support)
i=i+1 does not increment
Hi all,
I have a problem with the repeat-until routine.
I have something like this:
Let>i=0
repeat>i
Let>i=i+1
//Do something
until>i>100
If I have the loop running without much in it, everything works fine. If the loop takes longer (in my case one iteration would take about 0.5hour with long waits in it), the Let>i=i+1 is ignored. If I set a breakpoint just before the increment-line and go step-by-step, I can see that the first iteration is correct, i=1. But next time i stays at 1.
Somebody has an idea?
Thanks...
Regards horscht
I have a problem with the repeat-until routine.
I have something like this:
Let>i=0
repeat>i
Let>i=i+1
//Do something
until>i>100
If I have the loop running without much in it, everything works fine. If the loop takes longer (in my case one iteration would take about 0.5hour with long waits in it), the Let>i=i+1 is ignored. If I set a breakpoint just before the increment-line and go step-by-step, I can see that the first iteration is correct, i=1. But next time i stays at 1.
Somebody has an idea?
Thanks...
Regards horscht
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
That code works fine for me. I think we need to see the rest of your code. Quite likely there is something else in your code which is changing the value of i. Use Tools/Variable Explorer to see where i is being set.
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?
So here´s the code. i is change nowhere. It´s just used to select the line to read in the first file.
With the breakpoint at the end (right before the until) I can see, that i is still one after the first looping and going step by step through the first lines of the repeat-loop, i just stays one.
Edit: I have deleted the parts of the code, that didn´t matter for the solution of my problem...
With the breakpoint at the end (right before the until) I can see, that i is still one after the first looping and going step by step through the first lines of the repeat-loop, i just stays one.
Code: Select all
Let>WW_TIMEOUT=5
CapsOff
/**BREAKPOINT**/
Let>j=0
Repeat>j
//**BREAKPOINT**
Add>j=1
//Read a line in sws.txt and write it to new.txt
ReadLn>C:\somepath\somefile.txt,j,SWSstrLine
If>SWSstrLine=##EOF##,finish
//Message>SWSstrLine
WriteLn>C:\somepath\new.txt,1,SWSstrLine
Endif
Until>j>100
Last edited by horscht13 on Sun Dec 21, 2008 2:37 pm, edited 1 time in total.
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Actually your loop counter is j not i.
And you're trying to increment it with the Add command. But you have the syntax wrong. You have:
Add>j=1
You should have:
Add>j,1
Or:
Let>j=j+1
And you're trying to increment it with the Add command. But you have the syntax wrong. You have:
Add>j=1
You should have:
Add>j,1
Or:
Let>j=j+1
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?
Ok, sorry. Obviously that was no working version. I just tried different things to get it to work. (Changing i to j and using the add command were some of them)
I now figured out, that as long as there is no i,j,k or whatever in the ReadLn it works. But if there is (as is in Line 10) the increment command just doesn´t work. Can someone confirm this? Somebody a solution?
I now figured out, that as long as there is no i,j,k or whatever in the ReadLn it works. But if there is (as is in Line 10) the increment command just doesn´t work. Can someone confirm this? Somebody a solution?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Actually I see the problem. It is your WriteLn line. You have specified 1 as the return variable. So you are creating a variable called 1, set to whatever the result of the WriteLn command is. This is probably zero (success). So 1 becomes 0. You say j=j+1. j starts off as 1. 1 then becomes zero. 1+0 is 1. So j is set to 1 in every iteration.
Replace the 1 in WriteLn with a sensible variable name.
The problem is not with your ReadLn line.
Replace the 1 in WriteLn with a sensible variable name.
The problem is not with your ReadLn line.
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?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
ReadLn reads a line from a file and therefore is given the line number to read. The second parm is the line number.
WriteLn writes a line to the END of a file. The second parm is the variable to store the result of the operation.
WriteLn writes a line to the END of a file. The second parm is the variable to store the result of the operation.
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?
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
2 days? 2 hours according to the forum timestamp.
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?
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
A general guideline is not to use variables of only 1 character, it is too easy to have other values assigned to them by mistake. I usually name most of my variables with a meaningful name, starting with lowercase "v" for variable for easy identification.
Let>vLoop1=0
Repeat>vLoop1
//**BREAKPOINT**
Add>vLoop1,1
//Read a line in sws.txt and write it to new.txt
ReadLn>C:\somepath\somefile.txt,%vLoop1%,SWSstrLine
If>SWSstrLine=##EOF##,finish
//Message>SWSstrLine
WriteLn>C:\somepath\new.txt,vLine1,SWSstrLine
Endif
Until>vLoop1>100
Note that I usually surround my variables in formulas/commands with "%" so that I can see the actual value in the log files. But do not use %vVariable% format when assigning a value to it.
Let>vLoop1=0
Repeat>vLoop1
//**BREAKPOINT**
Add>vLoop1,1
//Read a line in sws.txt and write it to new.txt
ReadLn>C:\somepath\somefile.txt,%vLoop1%,SWSstrLine
If>SWSstrLine=##EOF##,finish
//Message>SWSstrLine
WriteLn>C:\somepath\new.txt,vLine1,SWSstrLine
Endif
Until>vLoop1>100
Note that I usually surround my variables in formulas/commands with "%" so that I can see the actual value in the log files. But do not use %vVariable% format when assigning a value to it.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
You can also use VAREXPLICIT to avoid issues like this.
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?