Missing something

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
Giles.Buist
Newbie
Posts: 15
Joined: Wed Feb 15, 2006 2:25 pm
Location: London

Missing something

Post by Giles.Buist » Wed Feb 15, 2006 2:30 pm

Hi people,

I have just started using Macro Scheduler. I am currently having problems with a loop. I have read all the other posts about issues with loops but have not been able to solve the problem.

The code is as shown below:



Let>P_PriceQuery=10
Let>P_Refund=20

Let>TT=0

Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Maximise.scp

Repeat>TT

// Choose which functionality to run

Random>100,R1

If>R1C:\Rec1.txt,1,PriceQuerying
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\PriceQuery.scp
Endif

If>R1>P_PriceQuery
If>R1C:\Rec1.txt,1,Refunding
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Refund.scp
Endif
Endif

If>R1>P_Refund
WriteLn>C:\Rec1.txt,1,Selecto
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\ItemSelect.scp
Endif

WriteLn>C:\Rec1.txt,1,TT
Let>TT=TT+1
Until>TT=3

Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Minimise.scp



The problem is that the loop is not stopping after three times, it just continues indefinietly. As you can see I have been logging the value of the Loop, this is always 0, it never increases as it should.

All help would be much appreciated

User avatar
JRL
Automation Wizard
Posts: 3532
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Feb 15, 2006 4:36 pm

Change the 1 in the WriteLn statement to something innocuous. I like to use "wresult". What you are doing is setting "1" to the value of the result of WriteLn. Therefore when you add TT and "1" you are probably adding TT and 0.

WriteLn>C:\Rec1.txt,1,Selecto
becomes
WriteLn>C:\Rec1.txt,wresult,Selecto

Hope this makes sense,
Dick

Giles.Buist
Newbie
Posts: 15
Joined: Wed Feb 15, 2006 2:25 pm
Location: London

Post by Giles.Buist » Wed Feb 15, 2006 5:07 pm

Have tried that, even tried removing the whole "WriteLn>" line but still looping continuously.

Any more suggestions?
I'll take anything?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Wed Feb 15, 2006 5:40 pm

You have THREE WriteLn statements in which you are setting the result of the operation to a variable called 1. Therefore when you later do TT=TT+1 you are adding the result of the WriteLn operation. Therefore TT is always larger than three and the loop will never end.

Change ALL THREE WriteLn statements.

You obviously haven't discovered the debugger yet - try it - if you step through with the watch list open you will see the problem immediately.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Giles.Buist
Newbie
Posts: 15
Joined: Wed Feb 15, 2006 2:25 pm
Location: London

Post by Giles.Buist » Thu Feb 16, 2006 9:13 am

The last "WriteLn>" statement records the value of TT, it always 0, not larger than 3 as you suggest it would be, always Zero, nought. Somehow the value of TT is being set to 0. Further, if the "Until>" line is changed to read "Until>TT>3" the code still repeats indefinietly.

I appreciate you trying to help, I really do, but I don't think we've found the problem yet. So please, any other suggestions?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Feb 16, 2006 9:39 am

I am not talking about what WritLn is OUTPUTTING. The problem is that you have 1 as the RESULT variable. You are setting the RESULT (not the output) of the WriteLn command to a variable called "1". So you make "1" equal to the result.

Your code should be:


Let>P_PriceQuery=10
Let>P_Refund=20

Let>TT=0

Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Maximise.scp

Repeat>TT

// Choose which functionality to run

Random>100,R1

If>R1C:\Rec1.txt,RES,PriceQuerying
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\PriceQuery.scp
Endif

If>R1>P_PriceQuery
If>R1C:\Rec1.txt,RES,Refunding
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Refund.scp
Endif
Endif

If>R1>P_Refund
WriteLn>C:\Rec1.txt,RES,Selecto
Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\ItemSelect.scp
Endif

WriteLn>C:\Rec1.txt,RES,TT
Let>TT=TT+1
Until>TT=3

Macro>C:\Program Files\MJT Net Ltd\Macro Scheduler\Minimise.scp


Please read the help file topic on WriteLn. You were creating a variable called "1". So when you add 1 to something you were adding the value of the variable "1" which was the outcome of the WriteLn operation - probably something like 32 or something!!!
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Giles.Buist
Newbie
Posts: 15
Joined: Wed Feb 15, 2006 2:25 pm
Location: London

Post by Giles.Buist » Thu Feb 16, 2006 1:20 pm

Ah, I do apologise you are right. Replacing the one with Res fixed the problem. Thankyou.

Since the WriteLn command was always succesful 1 was being set to zero.

This in itself confuses me, I am relatively new to coding but have learnt the basics of VB and Java. Am I right in thinking that in those languages you would not be able to use a number as a variable, ie. you wouldn't be able to give the number 1 a value of zero?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Feb 16, 2006 1:32 pm

You are correct. Macro Scheduler is simpler in that there is no distinction between variables and literals and that you can assign a value to anything. In any case you were providing 1 in the parameter for a return variable and therefore asking WriteLn to create a variable called 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?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts