Do loop with random wait time

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
trapedui
Newbie
Posts: 4
Joined: Tue Dec 07, 2010 2:44 pm

Do loop with random wait time

Post by trapedui » Tue Dec 07, 2010 3:17 pm

I have very little programming experience and am new here. I am trying to do a simple task, but can't quite get it to work. Basically, I want to have the macro do a left click (no need to move the mouse), wait a random amount of time between 0.15 seconds and 0.20 seconds, hit the letter "a", wait 0.25 - 0.30 seconds, then repeat 200 times.

I've made good progress. It now works with a fixed amount of wait time. Here is my macro that works (i'm typing from memory as I don't have access the the exact code right now, but it is pretty simple):

Code: Select all

Let>x=0
Repeat>x
  LClick
  Wait>0.20
  Send>a
  Wait>0.30
Let>x=x+1
Until>x=200
Then I tried to make the wait times random and it just doesn't work. Here is my code (again from memory):

Code: Select all

Let>x=0
Repeat>x
  LClick
  Random>101,RandATime
  Let>WaitTimeA = RandATime / 2000 + 0.15
  Wait>%WaitTimeA%
  Send>a
  Random>101,RandClickTime
  Let>WaitTimeClick = RandClickTime / 2000 + 0.25
  Wait>%WaitTimeClick%
Let>x=x+1
Until>x=200

When I ran the code, it does the first left click, but does not type the letter "a". Not sure why Any help would be appreciated. I won't be able to test the code untilt his evening EST. Thanks.

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

Post by Marcus Tettmar » Tue Dec 07, 2010 3:38 pm

Hi,

Does this do it for you:

Code: Select all

Let>x=0
Repeat>x
  LClick
  GoSub>RandWait
  Send>a
  GoSub>RandWait
Let>x=x+1
Until>x=200

//waits a random time between 0.25 and 0.30 seconds
SRT>RandWait
  Random>5,rndRange
  Let>rndTime={(%rndRange%+25)/100}
  Wait>rndTime
End>RandWait
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

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

trapedui
Newbie
Posts: 4
Joined: Tue Dec 07, 2010 2:44 pm

Post by trapedui » Tue Dec 07, 2010 4:42 pm

Thank you very much Marcus. I will try it tonight. I haven't done much programming since I was a 12yo with an Atari 400, but I can follow what you've done. If I don't post again, you can assume this is "case closed".

Cheers!

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